将表单数据插入数据库故障

时间:2016-02-28 04:53:26

标签: php mysql mysqli

好吧所以我现在正在尝试建立一个系统来接受应用程序,直到我添加了其余的问题它才开始工作:

<?php
include_once('db.php');

$user =$_POST['username'];
$job =$_POST['job'];
$active =$_POST['active'];
$why =$_POST['Q1']
$le =$_POST['Q2']
$skype =$_POST['skype']

if(mysqli_query($conn, "INSERT INTO app (username,job,active,why,le,skype) VALUES ('$user','$job','$active','$why','$le','$skype')"))
echo"successfully inserted";
else
echo "failed";
?>

但是当我得到它时,我得到了这个错误

  

解析错误:语法错误,第8行的C:\ xampp \ htdocs \ app_insert.php中的意外'$ le'(T_VARIABLE)

请记住我在Apache和Mysql中使用xampp,有谁知道发生了什么事?

2 个答案:

答案 0 :(得分:-1)

您错过了分号,;表示:

$why =$_POST['Q1']
$le =$_POST['Q2']
$skype =$_POST['skype']

应该是:

$why =$_POST['Q1'];
$le =$_POST['Q2'];
$skype =$_POST['skype'];

答案 1 :(得分:-1)

您缺少分号,并且插入SQL语句似乎不正确。您将字符串传递给SQL语句而不是值

<?php
include_once('db.php');

$user =$_POST['username'];
$job =$_POST['job'];
$active =$_POST['active'];
$why =$_POST['Q1'];
$le =$_POST['Q2'];
$skype =$_POST['skype']

if(mysqli_query($conn, "INSERT INTO app (username,job,active,why,le,skype) VALUES ('{$user}','{$job}','{$active}','{$why}','{$le}','{$skype}')"))
echo"successfully inserted";
else
echo "failed";
?>