我對形式的PHP代碼:錯誤插入數據到MySQL數據庫
body{
\t margin:0;
}
#top_nav{
\t background-color:#000;
\t height:auto;
\t max-height:3em;
}
#top_nav a{
\t text-decoration:none;
\t color:#FFF;
\t font-family:Arial, Helvetica, sans-serif;
}
.menu{
\t display:inline-block;
\t padding:1em;
\t font-size:1em;
\t height:1em;
}
.menu:hover{
\t background-color:#09F;
\t border-bottom-left-radius:2em;
\t border-bottom-right-radius:2em;
\t height:3em;
\t -webkit-transition:height 500ms ease;
\t -moz-transition:height 500ms ease;
\t -ms-transition:height 500ms ease;
\t -o-transition:height 500ms ease;
\t transition:height 500ms ease;
}
#contact-us{
\t color:#09F;
}
#contact-us:hover{
\t color:#FFF;
}
#container{
\t margin-top:5%;
}
.textbox{
\t width:20em;
\t border-bottom:.1em solid #000;
\t border-top:0;
\t border-left:0;
\t border-right:0;
\t font-family:Arial, Helvetica, sans-serif;
\t font-size:2em;
\t height:2em;
\t border-bottom-left-radius:1em;
\t border-bottom-right-radius:1em;
\t -webkit-transition:all 500ms ease;
\t -moz-transition:all 500ms ease;
\t -ms-transition:all 500ms ease;
\t -o-transition:all 500ms ease;
\t transition:all 500ms ease;
\t padding:0 1em 0 1em;
\t margin-bottom:2%;
}
.textbox:focus{
\t outline:none;
\t border-bottom-color:#09F;
\t width:30em;
\t border-bottom-left-radius:1em;
\t border-bottom-right-radius:1em;
}
#textarea{
\t height:5em;
\t border-top:.1em solid #000;
\t border-top-left-radius:1em;
\t border-top-right-radius:1em;
\t resize:none;
}
#textarea:focus{
\t border-top-color:#09F;
}
.submit{
\t width:10em;
\t border-bottom:.1em solid #09F;
\t border-top:.1em solid #09F;
\t border-top-left-radius:1em;
\t border-top-right-radius:1em;
\t border-left:0;
\t border-right:0;
\t font-family:Arial, Helvetica, sans-serif;
\t font-size:2em;
\t color:#09F;
\t height:2em;
\t border-bottom-left-radius:1em;
\t border-bottom-right-radius:1em;
\t background-color:#000000;
\t -webkit-transition:all 500ms ease;
\t -moz-transition:all 500ms ease;
\t -ms-transition:all 500ms ease;
\t -o-transition:all 500ms ease;
\t transition:all 500ms ease;
}
.submit:hover{
\t border-top:.1em solid #000;
\t border-bottom:.1em solid #000;
\t background-color:#09F;
\t color:#000;
\t width:20em;
}
td{
\t text-align:center;
}
<html>
<head>
<title>Carzpedia | The best car search engine</title>
<link type="text/css" rel="stylesheet" href="css/contact-us.css"/>
<link rel="icon" href="images/favicon/favicon.ico"/>
</head>
<body>
<div id="top_nav"> <a href="index.php">
<div class="menu">CZP</div>
</a> <a href="list-of-car-manufacturers.php">
<div class="menu">LIST OF CAR MANUFACTURERS</div>
</a> <a href="why-use-carzpedia.php">
<div class="menu">WHY USE CARZPEDIA?</div>
</a> <a href="about-us.php">
<div class="menu">ABOUT US</div>
</a> <a href="contact-us.php">
<div class="menu" id="contact-us">CONTACT US</div>
</a> </div>
<div id="container">
<form method="post" action="php/send-data.php">
<table align="center">
<tr>
<td><input class="textbox" type="text" placeholder="Please enter full name..." name="name"/></td>
</tr>
<tr>
<td><input class="textbox" type="email" placeholder="Please enter email address..." name="eadd"/></td>
</tr>
<tr>
<td><input class="textbox" type="text" placeholder="Subject" name="subject"/></td>
</tr>
<tr>
<td><textarea class="textbox" id="textarea" placeholder="Description (Max 5000 characters)" name="description"></textarea>
</td>
</tr>
<tr>
<td align="center"><input class="submit" type="submit" value="SUBMIT" name="submit"/></td>
</tr>
</table>
</form>
</div>
</body>
</html>
<?php
//create connection
$con=mysqli_connect("localhost","root","","carzpedia");
//check connection
if(mysqli_connect_errno())
{
echo"Failed to connect to MySQL:".mysqli_connect_errno();
}
//get data from form
$name=$_POST['name'];
$eadd=$_POST['eadd'];
$subject=$_POST['subject'];
$description=$_POST['description'];
$date=date('Y-m-d h:i:sa');
//submit data
$sql="INSERT INTO 'contact us' (name,eadd,subject,description,date)
VALUES ('$name','$eadd','$subject','$description','$date')";
if(mysqli_query($con,$sql))
{
echo "Data submitted successfully";
}
else
{
echo"Error submitting data:".mysqli_error($con);
}
//close connection
mysqli_close($con);
?>
錯誤: 錯誤提交數據:您在您的SQL語法中有錯誤;請查看與您的MySQL服務器版本相對應的手冊,以便在''聯繫我們''(名稱,eadd,主題,描述,日期)附近使用正確的語法。VALUES('Sahil Sunny','sahils'at line 1
爲什麼你的表有一個空格分隔符,它會在進一步導致你很多問題 – 2014-09-21 08:24:54
那麼我有點新的PHP,所以我可能知道什麼是空格分隔符:)? – VOXRAZR 2014-09-21 08:59:40