为什么服务器会将第19行上的&#39 ;;'视为意外?

时间:2013-11-08 11:29:27

标签: php mysql sql

我一遍又一遍,但仍然无法解决为什么服务器告诉我它没有期待';'在第19行。以下是:

( '$ _ POST [modulecode]', '$ _ POST [学校]', '$ _ POST [日期]')“;

<?php


$link=mysqli_connect("bla","bla","bla","bla");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

 else
 {
 echo "Connection Succesfull";
 }


mysqli_query($link,"INSERT INTO student (tester, testertwo, testerthree)
VALUES 
    ('$_POST[modulecode]','$_POST[school]','$_POST[date]')";





if (!mysqli_query($link,$sql))
  {
  die('Error: ' . mysqli_error($link));
  }
echo "1 record added";








mysqli_close($link);


?>

4 个答案:

答案 0 :(得分:2)

您错过了)的右括号mysqli_query()

mysqli_query($link,"INSERT INTO student (tester, testertwo, testerthree)
VALUES 
    ('$_POST[modulecode]','$_POST[school]','$_POST[date]')");

答案 1 :(得分:0)

你错过了那里的右括号

  mysqli_query($link,"INSERT INTO student (tester, testertwo, testerthree) VALUES ('$_POST[modulecode]','$_POST[school]','$_POST[date]')");

一个建议总是先用简单的php回复你的查询...然后把它放到mysqli_query函数中..

答案 2 :(得分:0)

我喜欢用这种方式写它的部分原因(虽然我也会逃避任何和所有输入,无论我认为它来自哪里)......

$query = "
INSERT INTO student 
(tester
,testertwo
,testerthree
) VALUES 
('$_POST[modulecode]'
,'$_POST[school]'
,'$_POST[date]')
";

mysqli_query($link,$query);

答案 3 :(得分:0)

除了@Sirko所说的,我认为用括号之类的方式包装变量(包括字符串内部)是个好主意:

mysqli_query($link,"INSERT INTO student (tester, testertwo, testerthree) VALUES ('{$_POST[modulecode]}','{$_POST[school]}','{$_POST[date]}')");