Lambneck Posted April 13, 2008 Share Posted April 13, 2008 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! " ??? Link to comment https://forums.phpfreaks.com/topic/100950-display-submitted-form-info-from-database/ Share on other sites More sharing options...
poleposters Posted April 13, 2008 Share Posted April 13, 2008 Why have you got your table as the variable $table? Link to comment https://forums.phpfreaks.com/topic/100950-display-submitted-form-info-from-database/#findComment-516274 Share on other sites More sharing options...
Lambneck Posted April 13, 2008 Author Share Posted April 13, 2008 Just to make it cleaner and more efficient $table = 'ft_form_1'; Link to comment https://forums.phpfreaks.com/topic/100950-display-submitted-form-info-from-database/#findComment-516281 Share on other sites More sharing options...
atl_andy Posted April 13, 2008 Share Posted April 13, 2008 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. Link to comment https://forums.phpfreaks.com/topic/100950-display-submitted-form-info-from-database/#findComment-516284 Share on other sites More sharing options...
Lambneck Posted April 13, 2008 Author Share Posted April 13, 2008 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' Link to comment https://forums.phpfreaks.com/topic/100950-display-submitted-form-info-from-database/#findComment-516289 Share on other sites More sharing options...
atl_andy Posted April 13, 2008 Share Posted April 13, 2008 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']; } ?> Link to comment https://forums.phpfreaks.com/topic/100950-display-submitted-form-info-from-database/#findComment-516333 Share on other sites More sharing options...
Lambneck Posted April 14, 2008 Author Share Posted April 14, 2008 argh... still not displaying any submitted form data. thanks for the effort though. Link to comment https://forums.phpfreaks.com/topic/100950-display-submitted-form-info-from-database/#findComment-516374 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.