Jump to content

Archived

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

imimin

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

Recommended Posts

OK, I have that fixed but it is still not echoing???

Share this post


Link to post
Share on other sites

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

?>

Share this post


Link to post
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?

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

that would do it :) 

 

Out of curiosity does that throw a php error or simply convert it to 0?

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Did you change the (int) to mysql_real_escape_string() as suggested by gevans?

Share this post


Link to post
Share on other sites

Yesw and it gave me the following error:

 

Fatal error: Call to undefined function: myqsl_real_escape_string() in /homepages/27/d120150310/htdocs/poj/test1.php on line 69

Share this post


Link to post
Share on other sites

The function is spelled wrong, should be:

 

mysql_real_escape_string($_GET['cat']);

Share this post


Link to post
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.  :)

Share this post


Link to post
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'];

Share this post


Link to post
Share on other sites

Let's see if you're getting sql results now.

 

if(mysql_num_rows($get_items) > 0){
$item_row = mysql_fetch_assoc($get_items);
}else{
  die("No results found").
}

Share this post


Link to post
Share on other sites

Where should I insert this into my code?

Share this post


Link to post
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!

Share this post


Link to post
Share on other sites

Change your echo line to these 3 lines:

 

extract($item_row);
echo <<<HTML
<a href="{$sitelocation}{$url}?item_desc=$id">View details/order</a>
HTML;

Share this post


Link to post
Share on other sites

That did it!  Why did we have to pass the url like that, how does it work?

 

THANK YOU SO MUCH FOR ALL OF YOUR HELP!

Share this post


Link to post
Share on other sites

More than likely the query results contained an apostrophe which prematurely ended the anchor.  Using heredoc fixes that issue (as you can in the working example).

Share this post


Link to post
Share on other sites

If you have no more questions, could you mark the topic as solved?

 

Cheers,

p2grace

Share this post


Link to post
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!

 

Share this post


Link to post
Share on other sites

what is $sitelocation

 

Comes from the defs.php file (in include) which specifies a portion of the site url.

Share this post


Link to post
Share on other sites

Where is the item row being declared here?  Please post more of the script so we can troubleshoot.

 

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

Share this post


Link to post
Share on other sites

×

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.