YNWA Posted March 1, 2008 Share Posted March 1, 2008 I have created a table called 'review' which allows users to add details of a book. I have fields: bookID - int userEmail - varchar author - varchar bookTitle - varchar bookDescription - text price = varchar However, when I go to my ADD page, I the price field shows, I enter details and I get my message BOOK ADDED, which is correct. However when I go to the View Review page, two fields do not show. The userEmail does not appear, and the price field, everything else shows. Here is some code from my files: View Review Page // contruct the SQL $sql = "SELECT bookID, userEmail, bookTitle, author, bookDescription, price FROM review WHERE author = '$_POST[sel_review]'"; // Execute the SQL $result = mysql_query($sql,$conn); while ($newArray = mysql_fetch_array($result)) { $bookID = $newArray['bookID']; $userEmail = $newArray['userEmail']; $bookTitle = $newArray['bookTitle']; $author = $newArray['author']; $bookDescription = $newArray['bookDescription']; $price = $newArray['price']; } echo " <table width=\"500\" border=\"0\"> <tr> <td><strong>Book ID</strong></td> <td>$bookID</td> </tr> <tr> <td width=\"128\"><strong>User Email</strong></td> <td width=\"157\">$userEmail</td> </tr> <tr> <td><strong>Book Title</strong> </td> <td>$bookTitle</td> </tr> <tr> <td><strong>Author</strong> </td> <td>$author</td> </tr> <tr> <td colspan=\"2\"><strong>Book Description</strong> </td> <td width=\"500\">$bookDescription</td> </tr> <tr> <td><strong>Sale Price</strong> </td> <td>$price</td> </tr> </table> "; echo "<form method=\"POST\" action=\"$SERVER[php_SELF]\"> <input type=\"submit\" name=\"submit\" value=\"View Another\"> </form>"; } Add Book Page // has the form been viewed yet? if ($_POST[op] != "yes") { // Build the form to enable the data to be added echo "Hello ".$_SESSION['user']; echo " <form method=\"post\" action=\"$_SERVER[php_SELF]\"> <table width=\"659\" border=\"0\"> <tr> <td width=\"93\"><strong> Book Title: </strong></td> <td width=\"556\"><label> <input type=\"text\" name=\"bookTitle\" /> </td> </tr> <tr> <td><strong> Author: </strong></td> <td> <input type=\"text\" name=\"author\" /> </td> </tr> <tr> <td height=\"30\" colspan=\"2\"><strong> Book Description: </strong> <input type=\"hidden\" name=\"op\" value=\"yes\" /> </td> </tr> <tr> <td height=\"101\" colspan=\"2\"><textarea name=\"bookDescription\" cols=\"38\" rows=\"5\"></textarea></td> </tr> <tr> <td><strong>Sale Price: </strong></td> <td> <input type=\"text\" name=\"price\" /> </td> </tr> <tr> <td><input type=\"submit\" name=\"Submit\" value=\"Add Book\" /></td> </tr> </table> </form> "; } else { // Create a connection with the SQL server $conn = mysql_connect("localhost", "root", ""); // Select the correct database mysql_select_db("will",$conn); // contruct the SQL $sql = "INSERT INTO review (userEmail, bookTitle, author, bookDescription, price) VALUES ( '$_SESSION[user]', '$_POST[bookTitle]', '$_POST[author]', '$_POST[bookDescription]', '&_POST[price]' )"; // Execute the SQL if (mysql_query($sql,$conn)) { echo "Congratualtions on adding your book!<p>You will be automatically redirected to view the book archive"; $sec = 2; // number of seconds until redirect header("Refresh: $sec; url=view_review.php"); } else { echo "Error, Please Check Details!<br />"; } } } Anyone think of anything? Cheers Will Quote Link to comment https://forums.phpfreaks.com/topic/93864-2-fields-in-mysql-table-not-appearing-on-webpage/ Share on other sites More sharing options...
toplay Posted March 1, 2008 Share Posted March 1, 2008 1) I don't see where you're passing $_POST[sel_review] value to the view_review.php script. You need to pass it perhaps in a session or in the URL and view_review.php will use $_GET to retrieve the value (and not $_POST). 2) If you're only going to be reading one row, then don't use a while loop in view_review.php - just do a fetch once. If your query is meant to retrieve more than one row, then you need to put the echo of the book info inside the while loop. Quote Link to comment https://forums.phpfreaks.com/topic/93864-2-fields-in-mysql-table-not-appearing-on-webpage/#findComment-480975 Share on other sites More sharing options...
YNWA Posted March 1, 2008 Author Share Posted March 1, 2008 1) I don't see where you're passing $_POST[sel_review] value to the view_review.php script. You need to pass it perhaps in a session or in the URL and view_review.php will use $_GET to retrieve the value (and not $_POST). 2) If you're only going to be reading one row, then don't use a while loop in view_review.php - just do a fetch once. If your query is meant to retrieve more than one row, then you need to put the echo of the book info inside the while loop. I dont get what you mean? How can it work for other fields, ie. Author, Book Title, Description and BookID, but not show the price and userEmail fields? Quote Link to comment https://forums.phpfreaks.com/topic/93864-2-fields-in-mysql-table-not-appearing-on-webpage/#findComment-481025 Share on other sites More sharing options...
toplay Posted March 1, 2008 Share Posted March 1, 2008 Does $_SESSION['user'] hold a name or an email? In your insert change these things: Change: '$_SESSION[user]', To this: '{$_SESSION['user']}', Change: '&_POST[price]' to: '$_POST[price]' Quote Link to comment https://forums.phpfreaks.com/topic/93864-2-fields-in-mysql-table-not-appearing-on-webpage/#findComment-481043 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.