Q:

Data is not inserted into database

I would like to add data from an html form into the database , here is my code
<html><?php

$var1=$_POST[tag];
$var2=$_POST[name];
$var3=$_POST[surname];

echo $var1;
echo $var2;
echo $var3;

$dbhandle=mysql_connect('localhost','root','mysql')
or die ("Unable to connect to database");
 mysql_select_db("arduino");

mysql_query("INSERT INTO door('Tag','Name','Surname') VALUES('$var1','$var2','$var3')");
?>
</html>

However, none of the data enters the database, i have put the echo statements so as to show that data from the form is received and it all works fine, but when i open the db, 

select * from door 

returns empty set.

A:

You have quotes around your column names, so remove those
//Tag,Name,Surname

mysql_query("INSERT INTO door(Tag,Name,Surname) VALUES('$var1','$var2','$var3')");

                          ---^----^---^------^---

Note: Your code is vulnerable to SQL injection, also mysql_() API is now deprecated as of > PHP 5.5.0, consider using mysqli_() or PDO instead.

Read the big red box on php.net

You should always use error reporting in such cases, so if you are not going to use a different API, than use echo mysql_error($connection); which will give you a user friendly error message.

