Jump to content

Nooob alert! Simple, beginners table question


dslax27

Recommended Posts

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?

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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>"; 
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.