Jump to content

id number is being passed but not being used


dazzclub

Recommended Posts

Hi guys,

 

Ive been trying to pass an id number from one page to another, the id seems to get passed as its visible in the url, but the page/script is not using it to pull out the relevant data accordingly.

 

The browse_prints.php script is the one that sends the id number and the view_print.php script uses it to display the product.

 

I first tested the query (on the view_print.php script) that uses the id number on the mysql console, where by swapping the varible with an actual number and it worked, retrieving the right products accordingly.

 

here is the script for browse_prints.php

<?php #browse_prints.php
E_ALL; //displays any errors
//this page displays the availabl prints (products)

//set the page title and include the html header

$page_title = 'Browse the prints';
include('includes/header.html');

require_once('includes/mysqli_connect.php');

// Default query for this page:
$q = "SELECT artists.artist_id, CONCAT_WS(' ', first_name, middle_name, last_name) AS artist, print_name, price, description, print_id FROM artists, prints WHERE artists.artist_id = prints.artist_id ORDER BY artists.last_name ASC, prints.print_name ASC";

// Are we looking at a particular artist?
if (isset($_GET['aid']) && is_numeric($_GET['aid']) ) {
$aid = (int) $_GET['aid'];
if ($aid > 0) { // Overwrite the query:
	$q = "SELECT artists.artist_id, CONCAT_WS(' ', first_name, middle_name, last_name) AS artist, print_name, price, description, print_id FROM artists, prints WHERE artists.artist_id = prints.artist_id AND prints.artist_id = $aid ORDER BY prints.print_name";
}
}

//create the table head
echo '<table border="0" width="90%" cellspacing="3" cellpadding="3" align="center">
<tr>
<td align="left" width="20%"><b>Artist</b></td>	

<td align="left" width="20%"><b>Print Name</b></td>	

<td align="left" width="40%"><b>Description</b></td>	

<td align="right" width="20%"><b>Price</b></td>	

</tr>';

//display all the prints, linked to the urls
$r = mysqli_query($dbc, $q);

while($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {

//display each record
echo "\t<tr>
<td align=\"left\"><a href=\"browse_prints.php?aid={$row['artist_id']}\">{$row['artist']}</a></td>

<td align=\"left\"><a href=\"view_print.php?aid={$row['print_id']}\">{$row['print_name']}</a></td>

<td align=\"left\">{$row['description']}</td>

<td align=\"right\">{$row['price']}</td>

</tr>\n";

}//end of while loop.

echo '</table>';
mysqli_close($dbc);
include('includes/footer.html');
?>	

 

and here is the script for view_print.php

<?php #Script 17.6 - view_print.php
// This page displays the details for a particular print.

E_ALL;

$row = FALSE; // Assume nothing!

if (isset($_GET['pid']) && is_numeric($_GET['pid']) ) { // Make sure there's a print ID!

$pid =(int) $_GET['pid'];

// Get the print info:
require_once('includes/mysqli_connect.php');
$q = "SELECT CONCAT_WS(' ', first_name, middle_name, last_name) AS artist, print_name, price, description, size, image_name FROM artists, prints WHERE artists.artist_id = prints.artist_id AND prints.print_id = $pid";
$r = mysqli_query ($dbc, $q);
if (mysqli_num_rows($r) == 1) { // Good to go!

	// Fetch the information:
	$row = mysqli_fetch_array ($r, MYSQLI_ASSOC);

	// Start the HTML page:
	$page_title = $row['print_name'];
	include ('includes/header.html');

	// Display a header:
	echo "<div align=\"center\">
<b>{$row['print_name']}</b> by 
{$row['artist']}<br />";

	// Print the size or a default message:
	echo (is_null($row['size'])) ? '(No size information available)' : $row['size'];

	echo "<br />\${$row['price']} 
<a href=\"add_cart.php?pid=$pid\">Add to Cart</a>
</div><br />";

	// Get the image information and display the image:
	if ($image = @getimagesize ("../uploads/$pid")) {
		echo "<div align=\"center\"><img src=\"show_image.php?image=$pid&name=" . urlencode($row['image_name']) . "\" $image[3] alt=\"{$row['print_name']}\" /></div>\n";	
	} else {
		echo "<div align=\"center\">No image available.</div>\n"; 
	}

	// Add the description or a default message:
	echo '<p align="center">' . ((is_null($row['description'])) ? '(No description available)' : $row['description']) . '</p>';

} // End of the mysqli_num_rows() IF.

mysqli_close($dbc);

}

if (!$row) { // Show an error message.
$page_title = 'Error';
include ('includes/header.html');
echo '<div align="center">This page has been accessed in error!</div>';
}

// Complete the page:
include ('includes/footer.html');
?>

 

Any help would be great.

 

 

cheers

Darren

Link to comment
Share on other sites

From what i can see...

 

in browse_prints.php you send via URL the 'aid' var

<td align=\"left\"><a href=\"view_print.php?aid={$row['print_id']}\">{$row['print_name']}</a></td>

 

but in view_print.php you use $_GET['pid']

Should't this be $_GET['aid'] ?

 

Try puting $pid = $_GET['aid'] in your second file

Link to comment
Share on other sites

Hi there, thanks for that.

 

thats the problem, i was using...aid for both

<td align=\"left\"><a href=\"browse_prints.php?aid={$row['artist_id']}\">{$row['artist']}</a></td>
<td align=\"left\"><a href=\"view_print.php?aid={$row['print_id']}\">{$row['print_name']}</td>

 

When it should have been...aid[/b[ and pid for the other

<td align=\"left\"><a href=\"browse_prints.php?aid={$row['artist_id']}\">{$row['artist']}</a></td>
<td align=\"left\"><a href=\"view_print.php?pid={$row['print_id']}\">{$row['print_name']}</td>

 

so now the view_print.php get the id (pid) with....

if (isset($_GET['pid']) && is_numeric($_GET['pid']) ) { // Make sure there's a print ID!

$pid =(int) $_GET['pid'];

 

I stupidly copy and pasted the two links and for got to change accordingly.

 

thanks for your help..:)

 

cheers

Dazzclub

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.