语法错误,意外''(T_ENCAPSED_AND_WHITESPACE),期待标识符(T_STRING)或变量(T_VARIABLE)或数字(T_NUM_STRING)

时间:2013-11-08 12:56:10

标签: php sql wamp

您好我是PHP和SQL新手并且遇到了这些错误..

无法将数据附加到我的数据库,也无法找到后退空间......

我正在处理的代码是

提前感谢解决方案...

<?php
    $con=mysqli_connect("localhost","root","","nova");
    if (mysqli_connect_errno())
      {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
      }
    ;
    $sql="INSERT INTO signup_form(name,email,contact,subject,message) VALUES('$_POST['name']','$_POST['email']','$_POST['contact']','$_POST['subject']','$_POST['message']')";
    if(!mysqli_query($con,$sql))
      {
      die('Error: ' . mysqli_error($db));
      }
    echo "1 record added succesfully";

mysqli_close($con);
?>

NE

1 个答案:

答案 0 :(得分:3)

if阻止

后删除分号
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
;
^^ //remove this semicolon


您的查询也应该是

$sql="INSERT INTO signup_form(name,email,contact,subject,message) VALUES('".$_POST['name']."','".$_POST['email']."','".$_POST['contact']."','".$_POST['subject']."','".$_POST['message']."')";