Jump to content

[SOLVED] Help needed with passing 'id' through url


imimin

Recommended Posts

  • Replies 92
  • Created
  • Last Reply

Thank you for all of your help  :-X

 

<?php

if(!isset($_GET['cat'])){
   die("Category isn't specified");
}


/* Enable displaying of errors */
error_reporting(E_ALL);
ini_set('display_errors', 'On');

$cat = (int) $_GET['cat'];
$get_items = "SELECT * FROM poj_products WHERE cat='$cat'";
$get_items = mysql_query($get_items);
if($get_items){
   $item_row = mysql_fetch_assoc($get_items);
   echo '<a href="'.$sitelocation.$item_row['url'].'?item_desc='.$item_row['id'].'>view details/order</a>';
   echo $_GET['cat'];
}else{
   die("Unable to connect to database.".mysql_error());
}

?>

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

 

I advised this earlier as I thought by 'id' you meant an integet. But after looking at a later post it seems your using a string...

 

change $cat = (int) $_GET['cat'];

 

to

 

$cat = myqsl_real_escape_string($_GET['cat']);

 

as had already been mentioned by someone else.

Ok - assuming you're no longer getting the 'Category isn't specified' error... I'm not seeing where the $sitelocation variable is created, but it's being called in the echo string.

 

Is there any output at all?  Any php errors?

 

I am no longer getting the 'Category isn't specified' error. $sitelocation is coming from the def.php file and there are NO errors being reported.

the best thing to do is lern about php because i can see you running it to more errors what i think you have done is used a script you have found on the internet and you dont really understant what the code is doing.

 

but to say your a rockie thats pretty good what you done so far.  :)

Ok - assuming you're no longer getting the 'Category isn't specified' error... I'm not seeing where the $sitelocation variable is created, but it's being called in the echo string.

 

Is there any output at all?  Any php errors?

 

Thanks for your help!

 

I fixed the spelling and no more errors.  However, it is still not echoing, not even the:

 

echo $_GET['cat'];

Before we do that, let me explain something...

 

if I remove the echo line:

 

echo '<a href="'.$sitelocation.$item_row['url'].'?item_desc='.$item_row['id'].'>view details/order</a>';

 

the "echo $_GET['cat'];" prints fine.  But if I put the echo anchor tag back in, NOTHING PRINTS!

This code works fine:

 

<?php

if(!isset($_GET['cat'])){
   die("Category isn't specified");
}


/* Enable displaying of errors */
error_reporting(E_ALL);
ini_set('display_errors', 'On');

$cat = mysql_real_escape_string($_GET['cat']);

$get_items = "SELECT * FROM poj_products WHERE cat='$cat'";
$get_items = mysql_query($get_items);
if($get_items){
   $item_row = mysql_fetch_assoc($get_items);
   extract($item_row);
   echo <<<HTML
   <a href="http://www.patternsofjoy.com/test2.php?item_desc=$id">View details/order</a>
HTML;
   #echo '<a href="'.$sitelocation.$item_row['url'].'?item_desc='.$item_row['id'].'>view details/order</a>';
   echo $_GET['cat'];
}else{
   die("Unable to connect to database.".mysql_error());
}

?>

 

But when I pass the URL containing a pointer to the 'desc' in my DB to the next page (http://www.patternsofjoy.com/test2.php), nothing echoes?  I am pretty sure I have the code correct on the next page which is:

 

<?php
$item_desc = $_GET['item_desc'];
echo $item_row['desc'].'<br/><br/>';
?>

 

I am getting the3 error:

 

Notice: Undefined variable: item_row in /homepages/27/d120150310/htdocs/poj/test2.php on line 46

 

Line 46 is:

 

echo $item_row['desc'].'<br/><br/>';

 

Thank you!

 

Archived

This topic is now archived and is closed to further replies.

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