dslax27 Posted March 19, 2008 Share Posted March 19, 2008 I've read a lot of form / survey tutorials and forum posts over the past few days and I'm learning quite a bit. One problem: I am completely new to PHP, and unfortunately everything I've read assumes otherwise. My first PHP goal is to set up a form that perform the following actions: Save user data to a PHP database E-mail me a synopsis of each user's entry Show the user a confirmation of what they've submitted Any suggestions as to where should I get started? Would I be better off using a site like POG (http://www.phpobjectgenerator.com) since I am so new? Quote Link to comment Share on other sites More sharing options...
jeremyphphaven Posted March 19, 2008 Share Posted March 19, 2008 Buy this book Quote Link to comment Share on other sites More sharing options...
teng84 Posted March 19, 2008 Share Posted March 19, 2008 <a href="http://www.w3schools.com/php/php_mysql_insert.asp"> learn php mysql</a> <a href="http://www.w3schools.com/php/func_mail_mail.asp">mail</a> Quote Link to comment Share on other sites More sharing options...
dslax27 Posted March 19, 2008 Author Share Posted March 19, 2008 Would I need to read an entire book to understand what this tutorial is trying to teach(http://www.phpriot.com/articles/multi-step-wizards/1)? I think one of my biggest hurdles is understanding the relationship between the code and the database in my form example. Do I create the database table first and then have the code call on the table or vice versa? Quote Link to comment Share on other sites More sharing options...
jkewlo Posted March 19, 2008 Share Posted March 19, 2008 i looked at a lot of PH/MySQL tutorials on youtube.com Quote Link to comment Share on other sites More sharing options...
dslax27 Posted March 19, 2008 Author Share Posted March 19, 2008 Cool I'll get started with w3schools and youtube! Quote Link to comment Share on other sites More sharing options...
Braveheartt Posted March 19, 2008 Share Posted March 19, 2008 I highly suggest using these! MySQL tutorial PHP tutorial Both the above tutorials explain everything in small segments and also provide excellent examples, after just starting the tutorials I was able to copy the code and then edit to suit based on what I learned in the tutorials! If you use those, you'll be able to start your project straight away! Also you want to save the data into a MYSQL database. Here's the code you wanted, BUT you will need to make each part separate scripts or if statements to make sure certain things do not happen until the user has submitted the text etc. This code will show a text field and a button (along with every echo statement), when you click submit it will be emailed to the fake address and also show at the bottom what you submitted! But it needs changing of course! If you want it usable, you'll need to use your knowledge and go from there. (If you really can't figure it out, I'll do the parts for you, but at least try first, it‘s not hard at all once you know what you're doing!) Feel free to ask anything else about it though, and I'll gladly help out. <html> <!--This is our text field and button, go through the HTML tutorials on the sites above for more on making HTML forms!---> <center><body><form method="POST"> <input type="text" name="name" size="20"><br> <input type="submit" name="submit" value="Submit!"</body></center></form></html> <?php //Get the data from the text field $name = $_POST['name']; //Connect to MYSQL server mysql_connect("IP/localhost", "username", "password") or die(mysql_error()); //Connect to the database mysql_select_db("YourDatabase") or die(mysql_error()); // Create a MySQL table in the selected database (RUN THIS ONCE THEN COMMENT IT OUT!) mysql_query("CREATE TABLE YourTable( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), name VARCHAR(99))") or die(mysql_error()); //Insert the data mysql_query("INSERT INTO YourTable(name) VALUES('$name'") or die(mysql_error()); echo "<center><font color='blue'><h1>And that's it!!</h1></font></center>"; //Now let's email you a copy if(isset($_POST['submit'])) { $to = "youremail@yoursite.com"; $subject = "Any subject here, you could also make another $_POST call to get a subject the user inputs"; //Now the email's body $body = "From: $name"; //Now email the body! mail($to, $subject, $body); } //Finally let's show the user what they've emailed echo "<center>You have emailed: $name</center>"; ?> Quote Link to comment 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.