Jump to content

Recommended Posts

Notice: Undefined variable: id in C:\wamp\www\nyhungry\cart.php on line 247

cart.php?action=remove_item&ids=4&qty=1&register=1&id=0>Remove<

 

 

Why is the id variable coming undefined if I have set it up to pick up the value from the url on top!

 

That url that takes the user to cart has an value for id but when I click remove inside cart.php then it will refresh to inside the same cart.php and come back and shoe the rest of the items that has not been removed but then id returns as undefined empty? why if I am passing it in the string inside the string that wraps >remove<

 

Why is it returning undefined?

cart.php

<?php
$submenu = false;
$cat = isset($_GET['subject']) && is_numeric($_GET['subject'])?$_GET['subject']:null;
$prod = isset($_GET['menu']) && is_numeric($_GET['menu'])?$_GET['menu']:null; 
$menu_type = isset($_GET['menu_type']) && is_string($_GET['menu_type'])?$_GET['menu_type']:null;
$ids= (int) $_GET['ids'];
$id= (int) $_GET['id'];
?>	
<div id="cart5">
<p>
<a href=<?php echo "cart.php?action=remove_item&ids=" . $row["id"] .'&qty=1'. '&register='. $_GET['register']. '&id='.intval($id).""?>>Remove</a></p></div>

Link to comment
https://forums.phpfreaks.com/topic/189395-i-am-having-an-undefined-variable/
Share on other sites

I don't see how that warning can possibly come from that code.  The first mention of $id is

 

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

 

and the only warning that could generate is that the "id" index is not defined in $_GET.  The second mention is

 

a href=<?php echo "cart.php?action=remove_item&ids=" . $row["id"] .'&qty=1'. '&register='. $_GET['register']. '&id='.intval($id).""?>>Remove</a></p></div>

 

but $id was explicitly set above.  Even if $id is empty, it is still defined.

 

Are you sure the code you have pasted is line 247?

i have just verified again and line 247 is

 

<p>
<a href=<?php echo "cart.php?action=remove_item&ids=" . $row["id"] .'&qty=1'. '&register='. $_GET['register']. '&id='.intval($id).""?>>Remove</a></p>

 

 

the same line I have posted in the first post. I don't know why it is throwing that error because id= '. intval($id). and I don't know what's wrong with it.

 

It's entirely possible that that line generated the warning but ONLY if the earlier line that sets $id was not executed.  Perhaps it's inside a conditional like "if" ?

 

Can you put the entire script at pastebin.org and link to it?

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.