這裏是我的代碼:我是否正確寫入了INSERT查詢?
<?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"];
檢查$用戶是否在數據庫不是:
$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>";
}
}
}
?>
這裏是問題 - 我看不到任何問題。 – mvp 2013-05-14 09:03:19
但數據沒有插入db – 2013-05-14 09:04:25
javascript不是php – 2013-05-14 09:05:47