Jump to content

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


imimin

Recommended Posts

  • Replies 92
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

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());
}

?>

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

$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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.  :)

Link to comment
Share on other sites

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'];

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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!

 

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.