This is what I did, but it doesn´t work: - The database is called test - The table is also called test - There are three fields (name, email, city) - I got this code from a tutorial so i guess it must work. 1) First I created a file called form.html <form name="toSave" method="post" action="save_it.php"> <input type="text" name="name" size="20" /><br> <input type="text" name="email" size="20" /><br> <input type="text" name="city" size="20" /><br> <input type="submit" value="Submit"></form> 2) Then I created a file called save_it.php <?php $db=mysql_connect("localhost", "root", "") or die("Could not connect to localhost."); mysql_select_db("test", $db) or die("Could not find visitors."); $querySQL = "insert into test (d_name, d_email, d_city) values ($name, $email, $city)"; if(!$querySQL) error_message(sql_error()); ?> When I try to enter a new record through the html form it is not being added to the database, any ideas? Greetz Smetten
because after submitting the form,the values can be found in the $_POST array. so $_POST['name'] and $_POST['email'] and $_POST['city'] will contain the proper values not $name
what happens with this code... <?php $db=mysql_connect("localhost", "root", "") or die("Could not connect to localhost."); mysql_select_db("test", $db) or die("Could not find visitors."); $sql = "insert into `test` (`d_name`, `d_email`, `d_city`) values ('$name', '$email', '$city')"; $result = mysql_query($sql) or die(mysql_error() . '<br />' . $querySQL); ?> PHP: and yes, if register_globals is off you will need <?php $db=mysql_connect("localhost", "root", "") or die("Could not connect to localhost."); mysql_select_db("test", $db) or die("Could not find visitors."); $sql = "insert into `test` (`d_name`, `d_email`, `d_city`) values ('{$_POST['name']}', '{$_POST['email']}', '{$_POST['city']}')"; $result = mysql_query($sql) or die(mysql_error() . '<br />' . $querySQL); ?> PHP:
Thanx for your replies, I made the changes to my files but when i now push the submit button on the form, it asks if I want to download the file save_it.php