Jump to content

display submitted form info from database


Lambneck

Recommended Posts

Hello,

 

I have a form that collects a users Name, Email, Subject, and Message.

 

Once the form is submitted, I would like a page to display the

Subjects of these submitted forms as links.

when a link is clicked on a display page will open that displays

the form data in its entirety

(ie:name(database column: col_2), email(col_3), subject (col_4), message(col_5).

 

for example:

the user submits a form that collects their name, email, subject, and message.

all the subjects (col_4) from every user will be listed as links on one page.

then when a user clicks on a particular link it will open a page displaying the

form data that corresponds to the Subject link chosen.

 

I figured the only way to uniquely identify the link with its related form information would be by calling on its "submission_ID".

 

 

The links page I don't think has any problems but am showing it here to give an idea of what im doing:

 

if (!mysql_connect($db_host, $db_user, $db_pwd))
    die("Can't connect to database");

if (!mysql_select_db($database))
    die("Can't select database");
$result = mysql_query("SELECT col_4 FROM {$table} ORDER BY submission_date DESC");
if (!$result) {
    die("Query to show fields from table failed:".mysql_error());
}

while($row = mysql_fetch_array($result))
{
	echo '<a href="ResumeDisplay.php?id='.$row['submission_id'].'">'.$row['col_4'].'</a>';
	echo "<br />";

}
mysql_free_result($result);
?>

 

 

The display page is where Im not sure about where my error is occurring:

 

 


if (!mysql_connect($db_host, $db_user, $db_pwd))
    die("Can't connect to database");

if (!mysql_select_db($database))
    die("Can't select database");

$id = (int) $_GET['id']; // since the submission ID is named "id" in the query string!

$sql = "SELECT * FROM {$table} WHERE submission_id=$id";
$result = mysql_query($sql) or die("Error ". mysql_error(). " with query ". $sql);
if(mysql_num_rows($result) == 1){
$row = mysql_fetch_assoc($sql);
//print out information
}else{
echo 'That record ID does not exist!';
}
?>

 

 

with the code as it is now i get  "That record ID does not exist! "  ???

 

 

One correction needed:

$sql = "SELECT * FROM {$table} WHERE submission_id=$id";

 

You need to pass $id correctly

$sql = "SELECT * FROM {$table} WHERE submission_id='$id' ";

 

I would suggest using '$table' as well, but don't know if {$table} is good or bad.

 

 

 

when I use:

 

$sql = "SELECT * FROM '$table' WHERE submission_id='$id' ";

 

I get:

 

Error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''ft_form_1' WHERE submission_id='0'' at line 1 with query SELECT * FROM 'ft_form_1' WHERE submission_id='0'

Ok, I set up a test table called submit and got it to work this way:

<?php
$db = mysql_connect('host', 'user', 'pass') or die("Cannot connect");  // Added connection info

mysql_select_db('submit',$db);  // Add $db

$_GET['id'] = 1;  // This is for my test
$table = submit;  // This also

$id = (int) $_GET['id']; // since the submission ID is named "id" in the query string!

$query = "SELECT * FROM {$table} WHERE submission_id='$id' ";  // Using {$table} works ok
$result = mysql_query($query, $db);  // Added $db 

while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {   // I think your for loop should be a while loop, also add MYSQL_ASSOC
echo $row['id'];
}

?>

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.