這裏我試圖插入表course_student中的值。查詢運行成功,但在數據庫中插入值後,我沒有得到任何警報。檢查INSERT是否成功
<?php
if(isset($_POST['submit']))
{
$connect =new mysqli("localhost","root","","new");
if(!$connect)
{
die("Database connection Error".mysql_error());
}
//select database
if(mysqli_connect_errno())
{
die("Database selection Error".mysqli_connect_error());
}
$course=$_POST['select1'];
$userid=$_SESSION['user_id'];
$sql="INSERT INTO course_student (Courseid,Studentid)VALUES ($_POST[select1],'$userid')";
$result=$connect->query($sql);
if ($result)
{ ?>
<html>
<body>
<script>
alert("fail");
</script>
</body>
</html>
<?php
}
else
{
?>
<script>
alert("fail");
</script>
<?php
}
}
?>
那麼,你會得到什麼?什麼?一個錯誤?做傻事? – j08691
您是否嘗試過檢查mysql_error() - 或者它是mysqli * alternative? – LokiSinclair
爲了簡單起見,請刪除JS警報並添加簡單的回聲語句。 –