Jump to content

2 Fields in MySQL table not appearing on webpage


Recommended Posts

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

 

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.

 

 

 

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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