在这里,我试图在表 course_student 中插入值。查询运行成功,但在数据库中插入值后,我没有收到任何警报。
<?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
}
}
?>