By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,067 Members | 1,849 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,067 IT Pros & Developers. It's quick & easy.

I need help with having one form's results on one page for multiple answers.

Countess Rayne
P: 6
I am really new to php, but I want to help my husband have a site where his football friends fill out a form and that form posts all their results on one page. I have the form and the results page, but I can't get each person's results on the same page. Here's the site:

http://twilight-angel.net/vikings
Click on NFL Pool Picks to see what I'm talking about. Here's the code I am using for the top part:

<form action="form_process.php" method="post">
Name: <input type="text" name="name" /><br />
Email: <input type="text" name="email" /><br />
Week One Game One: <br />
<select multiple name="gameone">
<option value="washington">Washington Redskins</option>
<option value="minnesota">Minnesota</option>
</select><br />
<input type="submit" name="submit" value="Submit Data"/>
</form>

And here is my results page:

<form action="form_process.php" method="post">
Name: <?php echo $_POST["name"]; ?><br />
Email: <?php echo $_POST["email"]; ?> <br />
Game One Pick: <?php echo $_POST["gameone"]; ?><br />
<?php
echo "Submitted at ".date("m/d/Y : H:i:s A", time()); ?>


</form></br>

I'd really appreciate any help! Thank you.
Jan 9 '08 #1
Share this Question
Share on Google+
11 Replies


Markus
Expert 5K+
P: 6,050
So, you want every persons choice to be displayed? You'd need to use a database for that!

If you're able to use MySQL and set up a database on your server, i'd be happy to help. :)

Sorry if i didn't understand your question
Jan 9 '08 #2

Countess Rayne
P: 6
So, you want every persons choice to be displayed? You'd need to use a database for that!

If you're able to use MySQL and set up a database on your server, i'd be happy to help. :)

Sorry if i didn't understand your question
I'm still kind of new to MySQL too, but yeah, I do have access to it. I created a database. Now what do I need to do? Please try to be a little patient with me. XD I'm a fast learner sometimes, but I get confused easily. ;) Thank you for helping me!!
Jan 9 '08 #3

Markus
Expert 5K+
P: 6,050
I'm still kind of new to MySQL too, but yeah, I do have access to it. I created a database. Now what do I need to do? Please try to be a little patient with me. XD I'm a fast learner sometimes, but I get confused easily. ;) Thank you for helping me!!
Don't worry about it! Everyone's been where you are now.

Let me refresh my memory on what you want doing...
10 mins!
Jan 9 '08 #4

Markus
Expert 5K+
P: 6,050
Ok

we need to create a table in the database! We'll do that first.

Create a file: createTable.php
in that file:
[php]
<?php
mysql_connect("__server__", "__username__", "__pass__") or die("Error: ".mysql_error());
echo "mysql connected";
mysql_select_db("__name_of_db__") or die("Error: ".mysql_error());
echo "database selected";

// substitute the above credentials with your own!

$query = "CREATE TABLE `zones` (
`id` TINYINT( 3 ) UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR( 150 ) NOT NULL,
`email` VARCHAR( 150 ) NOT NULL,
`game_one` VARCHAR( 150 ) NOT NULL,
PRIMARY KEY ( `zid` )
)";
mysql_query($query) or die("Error: ".mysql_error()); // create the table
echo "Table created!";
?>
[/php]
Let me know how you get on wityh this part.
Jan 9 '08 #5

Countess Rayne
P: 6
Ok

we need to create a table in the database! We'll do that first.

Create a file: createTable.php
in that file:
[php]
<?php
mysql_connect("__server__", "__username__", "__pass__") or die("Error: ".mysql_error());
echo "mysql connected";
mysql_select_db("__name_of_db__") or die("Error: ".mysql_error());
echo "database selected";

// substitute the above credentials with your own!

$query = "CREATE TABLE `zones` (
`id` TINYINT( 3 ) UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR( 150 ) NOT NULL,
`email` VARCHAR( 150 ) NOT NULL,
`game_one` VARCHAR( 150 ) NOT NULL,
PRIMARY KEY ( `zid` )
)";
mysql_query($query) or die("Error: ".mysql_error()); // create the table
echo "Table created!";
?>
[/php]
Let me know how you get on wityh this part.
Ok. It says "mysql connecteddatabase selectedError: Key column 'zid' doesn't exist in table". Is that ok?
Jan 9 '08 #6

Markus
Expert 5K+
P: 6,050
[php]
$query = "CREATE TABLE `zones` (
`id` TINYINT( 3 ) UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR( 150 ) NOT NULL,
`email` VARCHAR( 150 ) NOT NULL,
`game_one` VARCHAR( 150 ) NOT NULL,
PRIMARY KEY ( `id` )
)";
mysql_query($query) or die("Error: ".mysql_error()); // create the table
echo "Table created!";
?>
[/php]

Frik, im such an idiot sometimes!

Shall worketh now!



















Hopefully..
Jan 9 '08 #7

Countess Rayne
P: 6
All right. That seemed to work. It says that the table is created. Next? :D
Jan 10 '08 #8

Markus
Expert 5K+
P: 6,050
Ok, so now we need to INSERT the values passed from the form into the database.

On the page that you're taken to after you select 'submit data' we're going to want to add this:

[php]
<?php
// connect to mysql and select the database!
/*
Stuff here to catch the input
I.E. $_POST[input_name];
You need to make the data safe though (mysql injection)!
Read and learn how to prevent it here
http://www.tizag.com/mysqlTutorial/mysql-php-sql-injection.php
*/

$query = "
INSERT INTO
`insert_table_name_here`
(name, email, game_one)
VALUES
('$name', '$email', '$game_one')";

$insert = mysql_query($query) or die(mysql_error());
if($insert){
echo "Inserted into table successfully";
} else {
echo "Markus did something wrong!";
}
[/php]
Jan 10 '08 #9

Countess Rayne
P: 6
All right. I got that part. :) Next?
Jan 10 '08 #10

Markus
Expert 5K+
P: 6,050
Now we want to get the data from the table!

[php]
// connection stuff!

$query = "SELECT * FROM `table_name_here`";
while($__row = mysql_fetch_array($query){
echo $__row['username_row']." - ".$__row['game_one_row']."<br />";
}
[/php]

from there you should be able to manipulate it to display how you want.

Remember to change: username_row and game_one_row to the correct row names!
Jan 10 '08 #11

Countess Rayne
P: 6
When I get to the main end, the last thing you posted, and add it, everything stops working all together. If I can catch you on MSN messanger tomorrow, I might be able to understand more clearly.

My grandmother just died, so that's the reason I haven't been online a whole lot. Coding or graphics seem to keep me from crying, so I'm throwing myself headfirst into this.

Anyways, I hope I'm not too annoying to you. I really appreciate all your help so far!
Jan 11 '08 #12

Post your reply

Sign in to post your reply or Sign up for a free account.