954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

survey for school grads... Another question

Hey Sorry to bug you guys again. I had one more question. As i am developing this program now i realize that i have no clue how to save the data to the database.

basically the whole point in making this program was to be able to export a table in my database that would store all the submitted data from the survey.

I will have like 30 questions and almost 400 grads. all that data needs to be recorded.

What is going to be the easiest table structure to do that type of thing?

Or is e-mail just going to end up being easier?

dani190
Junior Poster in Training
63 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
 
CREATE TABLE test (
id INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
name VARCHAR( 100 ) NOT NULL ,
address VARCHAR( 100 ) NOT NULL
) ENGINE = InnoDB

If that's my table, and I have a form with 2 fields name and address, this is how I would be inserting the values to the table test. This should get you started.(I hope!)

<?php
if(isset($_POST['submit'])){
$conn=mysql_connect("localhost","root");
mysql_select_db("exact");
$name=$_POST['name'];
$address=$_POST['address'];
$query="INSERT INTO TEST (ID,NAME,ADDRESS) VALUES ('','$name','$address')";
mysql_query($query);
}
?>
<html>
<body>
<form method="post" action="insert_example.php">
Enter Name: <input type="text" name="name">
Enter Address: <textarea rows="10" cols="20" name="address"></textarea>

<input type="submit" name="submit" value="submit">
</form>
</body>
</html>


Cheers,
Nav

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

so if i wanted to send all the results via e-mail i would do something similar? i am going to search on that site you gave me and that book lets see if i can get it....

I found out how to mail it i just need some help with the security now.

I want to stop people from just going to the page vote.php, i want them going through the login how is that done?

dani190
Junior Poster in Training
63 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
 

You can use mail function.
Eg.
mail("to address","subject","message contents","from: from address");

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

so i know that part but how do i then integrate it with the submit button? And how do i tell the mail function what to mail... Like what form questions I wasnt able to find out how to do that yet

dani190
Junior Poster in Training
63 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
 

Well, you can have a condition to check if the submit button was pressed.

if(isset($_POST['submit'])){
$message="This is the body of this mail. blah blah blah..........some more text... ";
mail("test@gmail.com","test mail",$message,"from: someone@gmail.com");
}

you can send all the data in the message part of the mail.

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

ok so basically i can wrap that around the whole form were they are entering the info?

dani190
Junior Poster in Training
63 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
 

Yep. Get all the form information, align it as you want. Put it in the 'message' part of the mail.

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

k so 1 more thing

In the email part i dont know how to retrieve the persons answers from the folllowing...

<label>40. Funniest</label>
<select name="funniest">
  <option value="">Please Choose One Person</option>
  <option value="">Not Voting</option>
	<?php echo $option; ?>
</select>


...

Thanks, Dani

dani190
Junior Poster in Training
63 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
 

On submitting the page, if the user has selected a value from the select box, it will be in $_POST['funniest']. So, you can do something like $x=$_POST['funniest']. $x will have his selection.

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

just goes to show i dont know php enough yet... I actually bought another book so i will be learning it for sure.

Thank you very very much for your help, so glad someone was able to as i had to get this done.

Thanks again

dani190
Junior Poster in Training
63 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
 

Ok after about an hour of trying to figure this part out i wasn't able to....

So i have those variables

$a=$_REQUEST['priceisright'];


"I read that i should be using request and post in the message part obviouslly..."

Now when i go to e-mail

// Mail Script
if(isset($_POST['submit'])){
$message = "Thank you for registering with our site!\nYour selection was '{$_POST['style']}'.\n\nSincerely,\nUs";
mail("****@anblickstudios.com","Grad Survey 08",$message,"from: *****@anblickstudios.com");
}
?>


Now i am pretty sure i have the wrong format in this portion

'{$_POST['style']}'.


Mind helping me with my format there. I almost have it

dani190
Junior Poster in Training
63 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
 

no problemo! :)


Instead of {$_POST['style']}, you can assign that to a variable and use that variable. Its little confusing for starters on how php handles strings.

// Mail Script
if(isset($_POST['submit'])){
$selection=$_POST['style'];
$message = "Thank you for registering with our site!\nYour selection was $selection.\n\nSincerely,\nUs";
mail("****@anblickstudios.com","Grad Survey 08",$message,"from: *****@anblickstudios.com");
}
?>


You can do that.

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

so then for multiple selections i just use commas?

so it would be

$selection=$_POST['style'], $_POST['funniest'];


or can i just go and use what i already typed?

$a=$_POST['priceisright'];
$b=$_POST['millionaire'];
$c=$_POST['loosepassport'];
$d=$_POST['vanriver'];
$e=$_POST['spusecheat'];
$f=$_POST['marrymoney'];
$g=$_POST['5divorces'];
$h=$_POST['primeminister'];
$i=$_POST['teacheci'];


I am guessing that would work now wont it?

dani190
Junior Poster in Training
63 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
 

Yep. What you have done is correct.

$x=$_POST['field1'];
$y=$_POST['field2'];
$z=$_POST['field3'];
....

//In case you want to concat them, you can do it this way. 
$string = $x." ".$y." ".$z; //This will concat all the three variables separated by a space.
...


:) Hope that helps.

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

hmm only issue is it will still send me back nothing...

Thats so weird? I select something and it just sends me nothing

dani190
Junior Poster in Training
63 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
 

Try out a sample mail first to your own id. If you get it, then the problem is with your script. If you dont get a mail, then probably, your smtp is not configured properly.

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

sorry i didn't get what you said.

I get the e-mail it says this exactly

Thank you for registering with our site!
Your selection was .

Sincerely,
Us

dani190
Junior Poster in Training
63 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
 

ok..Then the problem is not with smtp.. Check if $_POST['style'] is sending a value.

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

lol sorry man i dont even know how to do that yet....

dani190
Junior Poster in Training
63 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You