Page 1 of 1

Getting form data to display

Posted: Tue Nov 16, 2004 12:39 pm
by kalvaris
Ok, so i have a form at http://openwar.net/php/test.php where user fills out the form and the information is placed in a database. Then the user can go to http://openwar.net/php/review.php so they can see what people have filled out the form. It displays the value in the field "first" in the table.

Then once they click the name it goes to a page that i cant figure out how to get it working. I want it to display all values in the field for the username that they select. For example, select steve and it will display everything steve filled out for the form.

Can anyone tell me how to get the information to display for the user selected. The link takes you to http://openwar.net/php/read.php?action=jackson where action=FIRSTNAME. So i want the values in the field where the first name = action to be displayed.

Thanks

steve

Posted: Tue Nov 16, 2004 2:35 pm
by kettle_drum

Code: Select all

$query = "SELECT * FROM users WHERE firstname = '{$_GET['action']}'";
And then run the query and display the results.

Posted: Tue Nov 16, 2004 3:52 pm
by kalvaris
How do i display the results tho (note im really new to mysql so the fact i even got the form to store the data was lucky for me)

Here is the code i have now for displaying the results of action=FIRST

Code: Select all

<?
$username="";
$password="";
$database="";

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "SELECT * FROM mac_form WHERE first = '&#123;$_GET&#1111;'action']&#125;'";
$result=mysql_query($query);



mysql_query($query);

echo "<b><center>Database Output</center></b><br><br>";

###HERE is where i want the info to be displayed

?>
Thanks
Steve

Posted: Tue Nov 16, 2004 4:13 pm
by kettle_drum
Ahh ok. For multiple results try:

Code: Select all

...
$result=mysql_query($query); 
while($row = mysql_fetch_assoc($result)){
   echo $row['field_in_database'];
}
And if you are only getting a single result from the database you dont need to add the code within a while loop and can simply use:

Code: Select all

...
$row = mysql_fetch_assoc($result);
echo $row['field_from_database'];