imimin Posted July 8, 2009 Author Share Posted July 8, 2009 OK, I have that fixed but it is still not echoing??? Quote Link to comment https://forums.phpfreaks.com/topic/165217-solved-help-needed-with-passing-id-through-url/page/2/#findComment-871420 Share on other sites More sharing options...
p2grace Posted July 8, 2009 Share Posted July 8, 2009 Can you post the most recent version of your code again Quote Link to comment https://forums.phpfreaks.com/topic/165217-solved-help-needed-with-passing-id-through-url/page/2/#findComment-871421 Share on other sites More sharing options...
imimin Posted July 8, 2009 Author Share Posted July 8, 2009 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()); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/165217-solved-help-needed-with-passing-id-through-url/page/2/#findComment-871426 Share on other sites More sharing options...
p2grace Posted July 8, 2009 Share Posted July 8, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/165217-solved-help-needed-with-passing-id-through-url/page/2/#findComment-871428 Share on other sites More sharing options...
gevans Posted July 8, 2009 Share Posted July 8, 2009 $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. Quote Link to comment https://forums.phpfreaks.com/topic/165217-solved-help-needed-with-passing-id-through-url/page/2/#findComment-871430 Share on other sites More sharing options...
p2grace Posted July 8, 2009 Share Posted July 8, 2009 that would do it   Out of curiosity does that throw a php error or simply convert it to 0? Quote Link to comment https://forums.phpfreaks.com/topic/165217-solved-help-needed-with-passing-id-through-url/page/2/#findComment-871432 Share on other sites More sharing options...
gevans Posted July 8, 2009 Share Posted July 8, 2009 Just convert it to a 0 Quote Link to comment https://forums.phpfreaks.com/topic/165217-solved-help-needed-with-passing-id-through-url/page/2/#findComment-871435 Share on other sites More sharing options...
imimin Posted July 8, 2009 Author Share Posted July 8, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/165217-solved-help-needed-with-passing-id-through-url/page/2/#findComment-871438 Share on other sites More sharing options...
p2grace Posted July 8, 2009 Share Posted July 8, 2009 Did you change the (int) to mysql_real_escape_string() as suggested by gevans? Quote Link to comment https://forums.phpfreaks.com/topic/165217-solved-help-needed-with-passing-id-through-url/page/2/#findComment-871440 Share on other sites More sharing options...
imimin Posted July 8, 2009 Author Share Posted July 8, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/165217-solved-help-needed-with-passing-id-through-url/page/2/#findComment-871449 Share on other sites More sharing options...
p2grace Posted July 8, 2009 Share Posted July 8, 2009 The function is spelled wrong, should be: Â mysql_real_escape_string($_GET['cat']); Quote Link to comment https://forums.phpfreaks.com/topic/165217-solved-help-needed-with-passing-id-through-url/page/2/#findComment-871454 Share on other sites More sharing options...
Danny620 Posted July 8, 2009 Share Posted July 8, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/165217-solved-help-needed-with-passing-id-through-url/page/2/#findComment-871460 Share on other sites More sharing options...
imimin Posted July 8, 2009 Author Share Posted July 8, 2009 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']; Quote Link to comment https://forums.phpfreaks.com/topic/165217-solved-help-needed-with-passing-id-through-url/page/2/#findComment-871466 Share on other sites More sharing options...
p2grace Posted July 8, 2009 Share Posted July 8, 2009 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"). } Quote Link to comment https://forums.phpfreaks.com/topic/165217-solved-help-needed-with-passing-id-through-url/page/2/#findComment-871469 Share on other sites More sharing options...
imimin Posted July 8, 2009 Author Share Posted July 8, 2009 Where should I insert this into my code? Quote Link to comment https://forums.phpfreaks.com/topic/165217-solved-help-needed-with-passing-id-through-url/page/2/#findComment-871480 Share on other sites More sharing options...
p2grace Posted July 8, 2009 Share Posted July 8, 2009 Post your entire code and I'll update it for you. Quote Link to comment https://forums.phpfreaks.com/topic/165217-solved-help-needed-with-passing-id-through-url/page/2/#findComment-871483 Share on other sites More sharing options...
imimin Posted July 8, 2009 Author Share Posted July 8, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/165217-solved-help-needed-with-passing-id-through-url/page/2/#findComment-871494 Share on other sites More sharing options...
p2grace Posted July 8, 2009 Share Posted July 8, 2009 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; Quote Link to comment https://forums.phpfreaks.com/topic/165217-solved-help-needed-with-passing-id-through-url/page/2/#findComment-871501 Share on other sites More sharing options...
imimin Posted July 8, 2009 Author Share Posted July 8, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/165217-solved-help-needed-with-passing-id-through-url/page/2/#findComment-871506 Share on other sites More sharing options...
p2grace Posted July 8, 2009 Share Posted July 8, 2009 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). Quote Link to comment https://forums.phpfreaks.com/topic/165217-solved-help-needed-with-passing-id-through-url/page/2/#findComment-871511 Share on other sites More sharing options...
p2grace Posted July 8, 2009 Share Posted July 8, 2009 If you have no more questions, could you mark the topic as solved? Â Cheers, p2grace Quote Link to comment https://forums.phpfreaks.com/topic/165217-solved-help-needed-with-passing-id-through-url/page/2/#findComment-871517 Share on other sites More sharing options...
imimin Posted July 9, 2009 Author Share Posted July 9, 2009 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!  Quote Link to comment https://forums.phpfreaks.com/topic/165217-solved-help-needed-with-passing-id-through-url/page/2/#findComment-871606 Share on other sites More sharing options...
Reaper0167 Posted July 9, 2009 Share Posted July 9, 2009 what is $sitelocation Quote Link to comment https://forums.phpfreaks.com/topic/165217-solved-help-needed-with-passing-id-through-url/page/2/#findComment-871611 Share on other sites More sharing options...
imimin Posted July 9, 2009 Author Share Posted July 9, 2009 what is $sitelocation  Comes from the defs.php file (in include) which specifies a portion of the site url. Quote Link to comment https://forums.phpfreaks.com/topic/165217-solved-help-needed-with-passing-id-through-url/page/2/#findComment-871614 Share on other sites More sharing options...
p2grace Posted July 9, 2009 Share Posted July 9, 2009 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/>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/165217-solved-help-needed-with-passing-id-through-url/page/2/#findComment-871624 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.