cazconv Posted April 20, 2010 Share Posted April 20, 2010 Hi guys, I am doing an assignment and i've stuck on one part, its a book club where the users can add reviews its after adding the reviews thats the problem. The user views the books details then clicks add review however once the submit button has been pressed all the book details disappear, i've tried meta refresh and header locations, i know i could hack the code around but i want a simpler solution any help would be awesome my codes below, thanks caroline x <?php // Store variables session_start(); // connect to database require_once('dbconnect.php'); // Include header and menu files include ('header.php'); include ('menu.php'); // Get varibles $bookID = $_REQUEST['bookISBN']; // clean variable from form $bookID = stripslashes($bookID); $bookID = mysql_real_escape_string($bookID); echo "<div class = \"Words\">"; echo "<b> Book Details </b>"; echo '</div>'; echo "<div class = \"cat\">"; // Get general book details $sql = "SELECT bookISBN, bookTitle, bookYear, bookPrice, pubID, catID FROM nbc_book where bookISBN = '$bookID'"; $res = mysql_query($sql); while ($row = mysql_fetch_array($res)) { $pubID = $row['pubID']; $catID = $row['catID']; echo '<br />'; echo "Title: " . $row['bookTitle']; echo '<br />'; echo "Year: " . $row['bookYear']; echo '<br />'; echo "Price: £" . $row['bookPrice']; echo '<br />'; } // Get Publisher Details $sql = "SELECT pubName, location FROM nbc_publisher where pubID = '$pubID'"; $res = mysql_query($sql); while ($row = mysql_fetch_array($res)) { echo "Publisher: " . $row['pubName']; echo '<br />'; echo "Location: " . $row['location']; echo '<br />'; } // Get genre $sql = "SELECT catDesc FROM nbc_category where catID = '$catID'"; $res = mysql_query($sql); while ($row = mysql_fetch_array($res)) { echo "Genre: " . $row['catDesc']; echo '<br />'; } echo '</div>'; echo "<div class = \"review\">"; echo "<b> Reviews </b>"; echo "</div>"; // Get Reviews already written echo "<div class = \"reviews\">"; $sql = "SELECT reviewText, reviewDate FROM nbc_bookreview where bookISBN = '$bookID' Order by reviewDate Desc"; $res = mysql_query($sql); while ($row = mysql_fetch_array($res)) { $review = $row['reviewText']; echo '<br />'; echo "Review Date: " . $row['reviewDate']; echo '<br />'; echo "Review: " . $row['reviewText']; echo '<br />'; } // if no reviews available if (empty($review)) { echo '<br />'; echo "There are no reviews at the moment"; } echo "<p><b> write your own review </b></p>"; // choose username echo "choose username"; $sql = mysql_query ("SELECT userName, userID FROM nbc_user"); // Start of form to php file echo '<form method= "get" action="review.php">'; echo '<p>'; echo '<select name = "user">'; while ($row = mysql_fetch_array($sql)) { $userName = $row['userName']; // Drop down options of usernaames echo "<option>"; echo $userName; echo "</option>"; } echo '</select>'; echo '<br />'; // input form for reviews echo 'Review:'; echo '<br />'; echo '<textarea rows= "4" cols="20" name = "review">'; echo '</textarea>'; echo '<br />'; echo "<input type=\"hidden\" name='bookid' value ='$bookID'/>"; echo '<input type="submit" value ="send review" style="background-color:#999999; color: #ffffff;" /></p>'; echo '</form>'; echo '</div>'; ?> </body> </html> <?php //store variables session_start(); // Connection to Database require_once('dbconnect.php'); include ('bookdetails.php'); $user = $_REQUEST['user']; // variables cleaned $user = stripslashes($user); $user = mysql_real_escape_string($user); $review = $_REQUEST['review']; // variables cleaned $review = stripslashes($review); $review = mysql_real_escape_string($review); $bookID = $_REQUEST['bookid']; // variables cleaned $bookID = stripslashes($bookID); $bookID = mysql_real_escape_string($bookID); $sql = "SELECT userID FROM nbc_user where userName = '$user'"; $res = mysql_query($sql); while ($row = mysql_fetch_array($res)) { $userID = $row['userID']; } $sql = "insert into nbc_bookreview (bookISBN, userID, reviewDate, reviewText) values ('$bookID', '$userID', now(), '$review')"; // run query if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } //else //{ //echo '<meta http-equiv="refresh" content="1;url=http://localhost/new/bookdetails.php?bookISBN=$bookID">'; //} ?> Link to comment https://forums.phpfreaks.com/topic/199127-keeping-dynamic-data-between-pages/ Share on other sites More sharing options...
aeroswat Posted April 20, 2010 Share Posted April 20, 2010 Well you are not getting the ISBN anymore correct? That's why its not getting the book details. What you should do is assign the ISBN to a hidden field in your form so that it is sent to the next php page and can then again be sent back to the original one. Either that or combine the two files so that you submit the form to itself. Link to comment https://forums.phpfreaks.com/topic/199127-keeping-dynamic-data-between-pages/#findComment-1045143 Share on other sites More sharing options...
cazconv Posted April 20, 2010 Author Share Posted April 20, 2010 Hi aeroswat, I am passing the ISBN in a hidden field echo "<input type=\"hidden\" name='bookid' value ='$bookID'/>"; What do you mean by combining the two files? Link to comment https://forums.phpfreaks.com/topic/199127-keeping-dynamic-data-between-pages/#findComment-1045212 Share on other sites More sharing options...
aeroswat Posted April 20, 2010 Share Posted April 20, 2010 Hi aeroswat, I am passing the ISBN in a hidden field echo "<input type=\"hidden\" name='bookid' value ='$bookID'/>"; What do you mean by combining the two files? Doing a if($_POST['Submit']) to check and see if the submit button was pressed on the page with the form and inside that if placing your code from the 2nd page. That way you can use your local variables instead. Also you will have to change the form action to the same page or nothing at all. Link to comment https://forums.phpfreaks.com/topic/199127-keeping-dynamic-data-between-pages/#findComment-1045216 Share on other sites More sharing options...
cazconv Posted April 20, 2010 Author Share Posted April 20, 2010 oh right thanks i get it now thanks for the help Link to comment https://forums.phpfreaks.com/topic/199127-keeping-dynamic-data-between-pages/#findComment-1045266 Share on other sites More sharing options...
cazconv Posted April 26, 2010 Author Share Posted April 26, 2010 Ok.... might have been a bit premature with the whole understanding what you meant, I changed the form to go back to itself and added the if post submit but the book details still disappear i just want them to stay on the same page when reviews are written if($_POST['submit']) { Link to comment https://forums.phpfreaks.com/topic/199127-keeping-dynamic-data-between-pages/#findComment-1048476 Share on other sites More sharing options...
aeroswat Posted April 26, 2010 Share Posted April 26, 2010 Ok.... might have been a bit premature with the whole understanding what you meant, I changed the form to go back to itself and added the if post submit but the book details still disappear i just want them to stay on the same page when reviews are written if($_POST['submit']) { In your html inputs you are going to have to set the default values to whatever your php variables are. So like this <input type="text" id="isbn" value="<?php echo $isbn; ?>" /> Link to comment https://forums.phpfreaks.com/topic/199127-keeping-dynamic-data-between-pages/#findComment-1048533 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.