1

My PHP code for the form:

body{
 margin:0;
}
#top_nav{
 background-color:#000;
 height:auto;
 max-height:3em;
}
#top_nav a{
 text-decoration:none;
 color:#FFF;
 font-family:Arial, Helvetica, sans-serif;
}
.menu{
 display:inline-block;
 padding:1em;
 font-size:1em;
 height:1em;
}
.menu:hover{
 background-color:#09F;
 border-bottom-left-radius:2em;
 border-bottom-right-radius:2em;
 height:3em;
 -webkit-transition:height 500ms ease;
 -moz-transition:height 500ms ease;
 -ms-transition:height 500ms ease;
 -o-transition:height 500ms ease;
 transition:height 500ms ease;
}
#contact-us{
 color:#09F;
}
#contact-us:hover{
 color:#FFF;
}
#container{
 margin-top:5%;
}
.textbox{
 width:20em;
 border-bottom:.1em solid #000;
 border-top:0;
 border-left:0;
 border-right:0;
 font-family:Arial, Helvetica, sans-serif;
 font-size:2em;
 height:2em;
 border-bottom-left-radius:1em;
 border-bottom-right-radius:1em;
 -webkit-transition:all 500ms ease;
 -moz-transition:all 500ms ease;
 -ms-transition:all 500ms ease;
 -o-transition:all 500ms ease;
 transition:all 500ms ease;
 padding:0 1em 0 1em;
 margin-bottom:2%;
}
.textbox:focus{
 outline:none;
 border-bottom-color:#09F;
 width:30em;
 border-bottom-left-radius:1em;
 border-bottom-right-radius:1em;
}
#textarea{
 height:5em;
 border-top:.1em solid #000;
 border-top-left-radius:1em;
 border-top-right-radius:1em;
 resize:none;
}
#textarea:focus{
 border-top-color:#09F;
}
.submit{
 width:10em;
 border-bottom:.1em solid #09F;
 border-top:.1em solid #09F;
 border-top-left-radius:1em;
 border-top-right-radius:1em;
 border-left:0;
 border-right:0;
 font-family:Arial, Helvetica, sans-serif;
 font-size:2em;
 color:#09F;
 height:2em;
 border-bottom-left-radius:1em;
 border-bottom-right-radius:1em;
 background-color:#000000;
 -webkit-transition:all 500ms ease;
 -moz-transition:all 500ms ease;
 -ms-transition:all 500ms ease;
 -o-transition:all 500ms ease;
 transition:all 500ms ease;
}
.submit:hover{
 border-top:.1em solid #000;
 border-bottom:.1em solid #000;
 background-color:#09F;
 color:#000;
 width:20em;
}
td{
 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>
My PHP code for inserting data:
<?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);
?>

Error: Error submitting data:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''contact us' (name,eadd,subject,description,date) VALUES ('Sahil Sunny','sahils' at line 1

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
VOXRAZR
  • 33
  • 1
  • 7

2 Answers2

0

You need to use backticks on tables instead of quotes. The identifier quote character is the backtick.

INSERT INTO `contact us` (name,eadd,subject,description,date)
            ^          ^ backticks not quotes (')
VALUES ('$name','$eadd','$subject','$description','$date')

Sidenote: I suggest since you are using mysqli, utilize prepared statements to execute safer queries.

Kevin
  • 41,694
  • 12
  • 53
  • 70
  • 1
    @OP -Or you can just treat tables without any particular quoting or backticking at all. Thats how I do it generally (http://stackoverflow.com/questions/11321491/when-to-use-single-quotes-double-quotes-and-backticks). Also, not part of the question but you should validate and sanitize input before putting it in a query (w prepared statements you just need to validate). – fast-reflexes Sep 21 '14 at 08:36
  • Thanx man you saved my day and about the validation i was just testing the submission i will add it later :) – VOXRAZR Sep 21 '14 at 08:58
  • @VOXRAZR sure glad it shed some light – Kevin Sep 21 '14 at 09:00
0

Use `contact us` instead of 'contact us' .

One more thing is that avoid space in table name.

Cheers.

Ravi Patel
  • 641
  • 1
  • 10
  • 18