Ollie Posted May 30, 2007 Share Posted May 30, 2007 Hi all, Im totally new to this site, PHP and MySql. Anyhow I have a Mysql DB up with tables constructed and modified and etc. I just started with PHP today and constructed my first Form in Dreamweaver to submit data via text fields to the MySQl DB. I guess what Im looking for is a code snippet I can reuse that submits the text in the form field to the corresponding DB field, in some cases some of the form field may be blank while others are populated. Anyone have a URL or code suggestion? (Ive looks through the library and tutorials I didnt see much) Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/53518-total-newb-need-php-form-to-mysql-help/ Share on other sites More sharing options...
eyalros Posted May 30, 2007 Share Posted May 30, 2007 Here you go: <? $done=$_POST["done"]; if ($done=="yes") { //This what the screen would look like after clicked "submit" $name=$_POST["name"]; $email=$_POST["email"]; $other=$_POST["other"]; include "connect.php"; //Connect to your DB... Either via "Include File" or just the connect query code mysql_query("INSERT INTO users(name, email, other) VALUES('$name', '$email', '$other')") or die(mysql_error()); echo "done!"; } else { ?> <form action="THE URL OF THIS PAGE" method="post"> Name: <input name="name"><br> E-mail: <input name="email"><br> Other: <input name="other"><br> <input type="submit"> </form> <? } ?> Just change the "name", "email" and "other" to your own needed values. you can add as much more values as you want - just copy/paste rows. Note that it's recommend to use ID in the DB, which is genarated automaticly and don't needed to be added manually by the mysql query. Eyal Quote Link to comment https://forums.phpfreaks.com/topic/53518-total-newb-need-php-form-to-mysql-help/#findComment-264523 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.