-2

在这里,我试图在表 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
}
}
?>
4

2 回答 2

0

第一 - 你可以echo "<script>alert('something')</script>";比你所拥有的更清楚,第二 -echo $result;并检查它的结果。

于 2013-07-17T19:17:42.873 回答
-2
  $sql="INSERT INTO course_student (Courseid,Studentid)VALUES ('".$_POST[select1]."','$userid')";
  $check = mysql_query($sql);
  if($check)
  {
  //If succeed
  }
于 2013-07-17T19:28:52.827 回答