Loathar Posted February 7, 2009 Share Posted February 7, 2009 I've been able to create/edit and display all records but I am trying to make a page that will diplay all the data for one record.... and be able to it it here is what i have for retrieving the record but its failing what am i doing wrong? I hate being such a Nub ---------------------------------------------------------------- <?php include("header.php"); ?> <?php include("library/db.php"); $Link = mysql_connect ($Host, $User, $Password); $Query = "Select FROM $TableName WHERE id='$_POST[id]'"; $Result = mysql_db_query ($DBName, $Query, $Link); /* In case of Error */ if (mysql_db_query ($DBName, $Query, $Link)) { // Fetch the Results while ($Row = mysql_fetch_array ($Result)) print ("<table width=800 border=0 cellspacing=0 cellpadding=0>\n"); print (" <tr>\n"); print (" <td width=50 ><img src=images/spacer.gif width=50 height=1></td>\n"); print (" <td class=text width=50 align=left><img src=images/spacer.gif width=50 height=1></td>\n"); print (" <td class=text width=200 align=left><img src=images/spacer.gif width=200 height=1></td>\n"); print (" <td class=text width=200 align=left><img src=images/spacer.gif width=200 height=1></td>\n"); print (" <td class=text width=200 align=left><img src=images/spacer.gif width=200 height=1></td>\n"); print (" <td class=text width=100 align=left><img src=images/spacer.gif width=100 height=1></td>\n"); print (" </tr>\n"); print (" <tr>\n"); print (" <td width=50> <img src= $Row[image] height=$imgh width=$imgw width=45></td>\n"); print (" <td class=text width=50 align=left>$Row[id]</td>\n"); print (" <td class=text width=200 align=left>$Row[name]</td>\n"); print (" <td class=text width=200 align=left>$Row[price]</td>\n"); print (" <td class=text width=200 align=left>$Row[description]</td>\n"); print (" <td class=text width=100 align=left><a href=$Row[purchase]>Armory Link</a></td>\n"); print (" </tr>\n"); print ("</table>\n"); } else { print ("<center><p class=note>REQUEST FAILED<br></center>\n"); } mysql_close ($Link); ?> <?php include("footer.php"); ?> ----------------------------------------------- This is the parent page ---------------------------------------------- <form Action=HandleEdit.php Method=Post enctype=multipart/form-data> <table width=550 border=0 align=center cellpadding=1 cellspacing=0 bgcolor=#333333> <tr> <td><table width=100% border=0 align=center cellpadding=4 cellspacing=0> <tr bgcolor=#000000> <td colspan=2 class=heading1>Edit a Member</td> </tr> <tr bgcolor=#eeeeee> <td class=text>Select a Member to Edit</td> <td><select name=id id=id> <?php include("library/db.php"); $Link = mysql_connect ($Host, $User, $Password); $Query ="SELECT * from $TableName ORDER BY name"; $Result = mysql_db_query ($DBName, $Query, $Link); // Before Selecte Menu // Fetch the Results while ($Row = mysql_fetch_array ($Result)) { print (" <option value=$Row[id]>$Row[name]</option>\n"); } mysql_close ($Link); // After Select menu ?> </select> </td> </tr> <tr bgcolor=#eeeeee> <td> </td> <td><input type=Submit name=Submit value=Edit></td> </tr> </table></td> </tr> </table> </form> Quote Link to comment Share on other sites More sharing options...
gaza165 Posted February 7, 2009 Share Posted February 7, 2009 <?php $Result = mysql_db_query ($DBName, $Query, $Link); ?> change this for some error detection, let us know if the query is failing and with what error <?php $Result = mysql_db_query ($DBName, $Query, $Link) or die(mysql_error()); ?> Quote Link to comment Share on other sites More sharing options...
Loathar Posted February 7, 2009 Author Share Posted February 7, 2009 OK I replace the line and here is the error i got back "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 'FROM products2 WHERE id='29'' at line 1" Quote Link to comment Share on other sites More sharing options...
gaza165 Posted February 7, 2009 Share Posted February 7, 2009 also i have noticed u dont have starting and closing brackets around your while loop. <?php /* In case of Error */ if (mysql_db_query ($DBName, $Query, $Link)) { // Fetch the Results while ($Row = mysql_fetch_array ($Result)) { // Start of while loop print ("<table width=800 border=0 cellspacing=0 cellpadding=0>\n"); print (" <tr>\n"); print (" <td width=50 ><img src=images/spacer.gif width=50 height=1></td>\n"); print (" <td class=text width=50 align=left><img src=images/spacer.gif width=50 height=1></td>\n"); print (" <td class=text width=200 align=left><img src=images/spacer.gif width=200 height=1></td>\n"); print (" <td class=text width=200 align=left><img src=images/spacer.gif width=200 height=1></td>\n"); print (" <td class=text width=200 align=left><img src=images/spacer.gif width=200 height=1></td>\n"); print (" <td class=text width=100 align=left><img src=images/spacer.gif width=100 height=1></td>\n"); print (" </tr>\n"); print (" <tr>\n"); print (" <td width=50> <img src= $Row[image] height=$imgh width=$imgw width=45></td>\n"); print (" <td class=text width=50 align=left>$Row[id]</td>\n"); print (" <td class=text width=200 align=left>$Row[name]</td>\n"); print (" <td class=text width=200 align=left>$Row[price]</td>\n"); print (" <td class=text width=200 align=left>$Row[description]</td>\n"); print (" <td class=text width=100 align=left><a href=$Row[purchase]>Armory Link</a></td>\n"); print (" </tr>\n"); print ("</table>\n"); } // End of while loop ---------------------- } else { print ("<center><p class=note>REQUEST FAILED<br></center>\n"); } mysql_close ($Link); ?> Quote Link to comment Share on other sites More sharing options...
gaza165 Posted February 7, 2009 Share Posted February 7, 2009 i see where u have gone wrong <?php $Query = "Select FROM $TableName WHERE id='$_POST[id]'"; ?> change the above line to <?php $Query = "Select * FROM $TableName WHERE id='$_POST[id]'"; ?> Quote Link to comment Share on other sites More sharing options...
Loathar Posted February 7, 2009 Author Share Posted February 7, 2009 Hmm this is an improvement for sure, but its not displaying information from the record, yet it still tries to display it. which is more than what i was getting b4 here is a link to the test app feel free to add and delete for testing to see how it works http://www.nuluce.com Quote Link to comment Share on other sites More sharing options...
gaza165 Posted February 7, 2009 Share Posted February 7, 2009 so it is showing some of the data?? is that right??? what is it not displaying?? Quote Link to comment Share on other sites More sharing options...
Loathar Posted February 7, 2009 Author Share Posted February 7, 2009 Sorry no the data fields are empty, but its spitting out the html table without an error. it seems to think that its getting the record but the page is not displaying it http://www.nuluce.com/update.php this is the page I'm referring to. Quote Link to comment Share on other sites More sharing options...
printf Posted February 7, 2009 Share Posted February 7, 2009 mysql_db_query () is DEPRECATED so stop using it! Use mysql_connect (), mysql_select_db(), and mysql_query () instead! Also don't assume anything, always validate user inputs. Also print, echo , require, include... are *language construct* so you don't need to use *()* to enclose their values. Here is an example with some code clean up, note, there is no right way to code in regards to coding style, this is just to give you an idea of how you might write a simple application that checks all of its actions before doing the next required action, "Logical Flow Control" <?php // form process page (HandleEdit.php) include 'header.php'; include 'library/db.php'; if ( isset ( $_POST['id'] ) ) { $Link = mysql_connect ( $Host, $User, $Password ) or die ( 'Database Connection Error: ' . mysql_error () ); mysql_select_db ( $DBName, $Link ) or die ( 'Select Database Error: ' . mysql_error () ); $Query = "SELECT * FROM $TableName WHERE id = '" . intval ( $_POST['id'] ) . "';"; $Result = mysql_query ( $Query, $Link ) or die ( 'Select Query Error: ' . mysql_error () ); if ( mysql_num_rows ( $Result ) > 0 ) { $Row = mysql_fetch_assoc ( $Result ); ?> <table width='800' border='0' cellspacing='0' cellpadding='0'> <tr> <td width='50' > <img src='images/spacer.gif' width='50' height='1'> </td> <td class='text' width='50' align='left'> <img src='images/spacer.gif' width='50' height='1'> </td> <td class='text' width='200' align='left'> <img src='images/spacer.gif' width='200' height='1'> </td> <td class='text' width='200' align='left'> <img src='images/spacer.gif' width='200' height='1'> </td> <td class='text' width='200' align='left'> <img src='images/spacer.gif' width='200' height='1'> </td> <td class='text' width='100' align='left'> <img src='images/spacer.gif' width='100' height='1'> </td> </tr> <?php echo " <tr> <td width='50' > <img src='" . $Row['image'] . "' width='" . $imgw . "' height='" . $imgh . "'> </td> <td class='text' width='50' align='left'> " . $Row['id'] . " </td> <td class='text' width='200' align='left'> " . $Row['name'] . " </td> <td class='text' width='200' align='left'> " . $Row['price'] . " </td> <td class='text' width='200' align='left'> " . $Row['description'] . " </td> <td class='text' width='100' align='left'> <a href='" . $Row['purchase'] . "'> Armory Link </a> </td> </tr> </table> "; } else { echo 'The query did not return a result set!'; } mysql_free_result ( $Result ); mysql_close ( $Link ); } else { echo 'The form input *id* was not submitted!'; } include 'footer.php'; ?> <?php // form submit page (?) include 'library/db.php'; $Link = mysql_connect ( $Host, $User, $Password ) or die ( 'Database Connection Error: ' . mysql_error () ); mysql_select_db ( $DBName, $Link ) or die ( 'Select Database Error: ' . mysql_error () ); $Query = "SELECT * FROM " . $TableName . " ORDER BY name;"; $Result = mysql_query ( $Query, $Link ) or die ( 'Select Query Error: ' . mysql_error () ); if ( mysql_num_rows ( $Result ) > 0 ) { ?> <form action='HandleEdit.php' Method='post'> <table width='550' border='0' align='center' cellpadding='1' cellspacing='0' bgcolor='#333333'> <tr> <td> <table width='100%' border='0' align='center' cellpadding='4' cellspacing='0'> <tr bgcolor='#000000'> <td colspan='2' class='heading1'> Edit a Member </td> </tr> <tr bgcolor='#eeeeee'> <td class='text'> Select a Member to Edit </td> <td> <select name='id' id='id'> <?php while ( $Row = mysql_fetch_assoc ( $Result ) ) { echo " <option value='" . $Row['id'] . "'>" . $Row['name'] . "</option>\n"; } ?> </select> </td> </tr> <tr bgcolor='#eeeeee'> <td> </td> <td> <input type='Submit' name='Submit' value='Edit'> </td> </tr> </table> </td> </tr> </table> </form> <?php } else { echo 'The query did not return any results!'; } mysql_free_result ( $Result ); mysql_close ( $Link ); ?> Quote Link to comment Share on other sites More sharing options...
Loathar Posted February 7, 2009 Author Share Posted February 7, 2009 BTW thank you for taking the time to help out. Quote Link to comment Share on other sites More sharing options...
gaza165 Posted February 7, 2009 Share Posted February 7, 2009 No worrys, what printf has said is a very good response and i would listen as he knows what hes talking about, let us know how you get on Quote Link to comment Share on other sites More sharing options...
Loathar Posted February 7, 2009 Author Share Posted February 7, 2009 WOW that's much cleaner.. I'm REALLY new to all php and mysql so it I appreciate your input! Quote Link to comment Share on other sites More sharing options...
Loathar Posted February 7, 2009 Author Share Posted February 7, 2009 at the risk of Noobing things up some more AMAZING you fixed it perfectly Thank you. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.