这是我的代码:
<?php
include('admin/class.php');
这是我的数据库连接:
$link = mysqli_connect("localhost", "root", "", "timesheet1234");
这是保存按钮的操作:
if(isset($_POST['save']))
{
$user=$_SESSION['user'];
$sel =$_POST["selpro"];
$mon =$_POST["mon"];
$tue =$_POST["tue"];
$wed =$_POST["wed"];
$thu =$_POST["thu"];
$fri =$_POST["fri"];
$sat =$_POST["sat"];
$sun =$_POST["sun"];
检查 $user 是否在 db 中:
$sql=mysqli_query($link,"select * from emp
where username='".$_SESSION['user']."'");
$res=mysqli_num_rows($sql);
在这里它检查是否插入不是:
if($res==0)
{
$sql1 = mysqli_query($link,"INSERT INTO emp SET username='$user',
project code='$sel',mon=$mon,tue=$tue,wed=$wed,
thu=$thu,fri=$fri,sat=$sat,sun=$sun");
问题来了:
if($sql1){
echo "<script type='text/javascript'>";
echo "alert('TimeSheet Saved..!')";
echo "</script>";
echo "<script type='text/javascript'>";
echo "window.location='my_tm.php'";
echo "</script>";
}
else
{
echo "<script type='text/javascript'>";
echo "alert('Some Error Occured ! Retry..!')";
echo "</script>";
echo "<script type='text/javascript'>";
echo "window.location='my_tm.php'";
echo "</script>";
}
}
}
?>