Jump to content

Link from a table entry


rich_northumbria

Recommended Posts

Hello

 

I am very new to PHP and doing some work for Uni. I was hoping for a little bit of guidance.

 

I am creating a website however here is a snippet as I test.

 

http://www.numyspace.co.uk/~unn_s007753/catList.php

 

When the user selects a category I am hoping to link the book title to the review page however I am unsure how to do this. ie wot sort of query to use.

 

Help but be greatly appreciated

Regards

Rich

Link to comment
Share on other sites

The link should be along the lines of echo "<a href=\"http://site.com/book_detail.php?id=$db_row['id']\">$db_row['title']</a>";

 

Then the query to retrieve the review uses the $GET['id'] parameter.

 

$id = (int) $_GET['id']

SELECT whatever_columns FROM whatever_table WHERE id = $id

 

Hope that makes sense.

Link to comment
Share on other sites

Attached is the code which I have currently.

 

Could you please explain using my code if possible as I seem to have errors

 

Can I ask a couple of questions on it please?

 

Some of the books within the drop down box are duplicated, how do I remove the duplication?

 

When you have selected a book how do I make the drop down box with the ISBN invisible but stay in the address bar?

 

http://www.numyspace.co.uk/~unn_s007753/testpage.php

 

Cheers

Rich

 

[attachment deleted by admin]

Link to comment
Share on other sites

You need to make sure your file.php?value=whatever in the url matches the value you're trying to retrieve with $_REQUEST. For example, in the displaybooklist1.php file, you look for the value of $_REQUEST['bookISBN'] coming from displaycatlist.php, but you're passing the value as '?name='. That causes the undefined index error, and the subsequent failure of the script to function as it should.

Link to comment
Share on other sites

From what I was able to see, the problems you're having are all related to the mismatches in the names of the variables. You need to change the <a href= url string in the displaycatlist.php script so the variable name is correct. ( ?bookISBN= rather than ?name= ) The best thing to do is test your pages, and pay attention to the error messages. Those should give you the information you need to track all of these down and correct them.

Link to comment
Share on other sites

The error is coming for this page:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">

<head>

<title>Northumbria Book Club</title>

<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />

</head>

<body>

<form action="reviewupdate.php" method="get">

<?php

//Connect to datebase

require_once('dbconnect.php');

//get the book from the request

$bookTitle = $_REQUEST['bookISBN'];

//Create SQL statement to retrieve the book

 

 

$booksSQL = "SELECT nbc_book.bookISBN, nbc_book.catID, nbc_book.bookYear,  nbc_book.bookTitle, nbc_book.bookPrice, nbc_authbook.authorID, nbc_author.authorName

    FROM nbc_book

    LEFT JOIN nbc_authbook

    ON nbc_book.bookISBN = nbc_authbook.bookISBN

    LEFT JOIN nbc_author

    ON nbc_authbook.authorID = nbc_author.authorID

    LEFT JOIN nbc_bookreview

    ON nbc_book.bookISBN = nbc_bookreview.bookISBN

where nbc_book.bookISBN = '$bookTitle';";

 

 

$rsbookDetails = mysql_query($booksSQL);

echo "<h1>Northumbria Book Club</h1>";

echo "<table border=\"1\">";

echo "<tr><th>Book ISBN</th><th>Book Title</th><th>Book Year</th><th>Author</th><th>Category</th><th>Price</th></tr>";

 

 

while($list = mysql_fetch_array($rsbookDetails)){

$bookISBN = $list['bookISBN'];

$bookTitle = $list['bookTitle'];

$bookYear = $list['bookYear'];

$authorName = $list['authorName'];

$catID    = $list['catID'];

$bookPrice = $list['bookPrice'];

 

 

echo "<tr><td>$bookISBN</td><td>$bookTitle</td><td>$bookYear</td><td>$authorName</td><td>$catID</td><td>$bookPrice</td></tr>";}

echo "</table>";

 

 

//Create SQL statement to retrieve the book

 

  $userSQL = "select userID, userName FROM nbc_user ORDER BY userName";

 

  $rsUserList = mysql_query( $userSQL );

 

  echo "<select name=\"userID\">";

  while($Ulist = mysql_fetch_array( $rsUserList )){

  $userID = $Ulist['userID'];

  $userName = $Ulist['userName'];

 

 

echo "<option value=\"$userID\">$userName</option>";}

echo "</select>";

 

$user1SQL = "SELECT nbc_book.bookISBN

 

FROM nbc_book";

 

$rsUserList1 = mysql_query( $user1SQL );

 

echo "<select name=\"bookISBN\">";

{

 

$userID = $Ulist1['bookISBN'];

 

echo "<option value=\"$bookISBN\">$bookISBN</option>";

}

 

echo "</select>";

 

 

  ?>

 

  </br>

 

<p>Upon selecting a book to review, please pick a user from the dropdown list above. Within the box probived state your views and opinions on the book and click “Submit Review”.</p>

<p><strong>Please note:</strong> It is more beneficial for other readers to have an appropiate review rather than a couple of words which does not describe the book.</p>

 

<p>Kind Regards</p>

<p>Northumbria Book Club</p>

 

<input type="text" name="reviewDate" value="<?php echo date("Y-m-d"); ?>" />

<input type="text" name="reviewText" />

<input type="submit" value="Submit Review"/>

 

<?php

$bookTitle = $_REQUEST['bookISBN'];

$reviewSQL = "SELECT nbc_bookreview.bookISBN, nbc_bookreview.userID, nbc_bookreview.reviewDate, nbc_bookreview.reviewText

    FROM nbc_book

    LEFT JOIN nbc_bookreview

    ON nbc_book.bookISBN = nbc_bookreview.bookISBN

where nbc_book.bookISBN = '$bookTitle';";

 

$rsreviw = mysql_query($reviewSQL);

echo "<h1>User Reviews</h1>";

echo "<table border=\"1\">";

echo "<tr><th>Book ISBN</th><th>User ID</th><th>Review Date</th><th>Review Text</th></tr>";

 

 

while($list = mysql_fetch_array($rsreviw)){

$bookISBN = $list['bookISBN'];

$userID = $list['userID'];

$reviewDate = $list['reviewDate'];

$reviewText= $list['reviewText'];

 

echo "<tr><td>$bookISBN</td><td>$userID</td><td>$reviewDate</td><td>$reviewText</td></tr>";}

echo "</table>";

 

?>

 

</form>

</body>

</html>

 

I believe its due to having  $bookTitle = $_REQUEST['bookISBN']; twice on the page however it causes further errors if i remove it.

 

Any advice

 

cheers

Link to comment
Share on other sites

Notice: Undefined index: bookISBN in /var/www/vhosts/numyspace.co.uk/web_users/home/~unn_s007753/public_html/displaybooklist1.php on line 13

 

 

Notice: Undefined index: bookISBN in /var/www/vhosts/numyspace.co.uk/web_users/home/~unn_s007753/public_html/displaybooklist1.php on line 94

 

Both these lines contain  $bookTitle = $_REQUEST['bookISBN'];

Link to comment
Share on other sites

OK. That all goes back to what I was saying earlier. The file that is sending the value to the displaybooklist.php script is not send the variable with the correct name. Here's an (oversimplified) example of what I mean:

 

form.php

<?php
// this sends a variable via the url to process.php. Note that I've misspelled 'number' in the url string
$number = 123456;
echo "<a href=\"process.php?numer=" . $number . "\">Send value</a>";
?>

 

process.php

<?php
$number = $_GET['number'];
echo $number;
?>

 

This will show an "undefined index" error on line 1 of process.php, even though the actual error is in form.php. That is what is happening to you. You're sending the proper value to the second script, but with the wrong name and it's triggering the undefined index errors, and not setting the variable values correctly. Does that help?

Link to comment
Share on other sites

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.