madjack87 Posted May 14, 2009 Share Posted May 14, 2009 Html Form <body> <form id="form1" name="form1" method="post" action="database1.php"> <p> <label for="name">Name:</label> <input type="text" name="name" id="name" tabindex="10" /> | </p> <p> <label for="email">Email:</label> <input type="text" name="email" id="email" tabindex="20" /> </p> <p> <label for="submit"></label> <input type="submit" name="submit" id="submit" value="Submit" /> <br /> </p> </form> </body> Php page <?php $username = "root"; $password = "password"; $database = "newletter"; $table = "contacts"; mysql_connect ('localhost',$username,$password); mysql_select_db($database) or die ("Could not connect"); $name = $_POST['name']; $email = $_POST['email']; $sql = "INSERT INTO $table(name,email) VALUES($name,$email)"; mysql_close(); ?> Link to comment https://forums.phpfreaks.com/topic/158131-from-a-html-form-to-a-mysql-database-i-need-help-check-my-code-please/ Share on other sites More sharing options...
BobcatM Posted May 14, 2009 Share Posted May 14, 2009 Are you recieving a error when you run it? Link to comment https://forums.phpfreaks.com/topic/158131-from-a-html-form-to-a-mysql-database-i-need-help-check-my-code-please/#findComment-834130 Share on other sites More sharing options...
madjack87 Posted May 14, 2009 Author Share Posted May 14, 2009 Are you recieving a error when you run it? Nope no error. When I check phpmyadmin no new records are added. Link to comment https://forums.phpfreaks.com/topic/158131-from-a-html-form-to-a-mysql-database-i-need-help-check-my-code-please/#findComment-834131 Share on other sites More sharing options...
madjack87 Posted May 14, 2009 Author Share Posted May 14, 2009 Here is the phpmyadmin image of the database Link to comment https://forums.phpfreaks.com/topic/158131-from-a-html-form-to-a-mysql-database-i-need-help-check-my-code-please/#findComment-834135 Share on other sites More sharing options...
funkyapache Posted May 14, 2009 Share Posted May 14, 2009 I would apply some validation to ensure that the email address is really an email address and that the name is not null etc. Also change your code on your insert to this $sql = "INSERT INTO $table(name,email) VALUES('$name','$email')"; I placed single quotes around your values as they will be strings. Link to comment https://forums.phpfreaks.com/topic/158131-from-a-html-form-to-a-mysql-database-i-need-help-check-my-code-please/#findComment-834136 Share on other sites More sharing options...
BobcatM Posted May 14, 2009 Share Posted May 14, 2009 You are not even using sql, you are just storing the data into $sql. Put this below your insert. mysql_query($sql); Link to comment https://forums.phpfreaks.com/topic/158131-from-a-html-form-to-a-mysql-database-i-need-help-check-my-code-please/#findComment-834137 Share on other sites More sharing options...
funkyapache Posted May 14, 2009 Share Posted May 14, 2009 something else you could try is to echo your insert statement to see if any values are being passed. Link to comment https://forums.phpfreaks.com/topic/158131-from-a-html-form-to-a-mysql-database-i-need-help-check-my-code-please/#findComment-834138 Share on other sites More sharing options...
madjack87 Posted May 14, 2009 Author Share Posted May 14, 2009 You are not even using sql, you are just storing the data into $sql. Put this below your insert. mysql_query($sql); THanks that worked Link to comment https://forums.phpfreaks.com/topic/158131-from-a-html-form-to-a-mysql-database-i-need-help-check-my-code-please/#findComment-834140 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.