co.ador Posted January 22, 2010 Share Posted January 22, 2010 Notice: Undefined variable: id in C:\wamp\www\nyhungry\cart.php on line 247 cart.php?action=remove_item&ids=4&qty=1®ister=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'. '®ister='. $_GET['register']. '&id='.intval($id).""?>>Remove</a></p></div> Quote Link to comment https://forums.phpfreaks.com/topic/189395-i-am-having-an-undefined-variable/ Share on other sites More sharing options...
premiso Posted January 22, 2010 Share Posted January 22, 2010 You need to also incorperate the isset on the ids: $ids= isset($_GET['ids'])?(int) $_GET['ids']:null; $id= isset($_GET['id'])?(int) $_GET['id']:null; Will remove that error. Quote Link to comment https://forums.phpfreaks.com/topic/189395-i-am-having-an-undefined-variable/#findComment-999743 Share on other sites More sharing options...
co.ador Posted January 22, 2010 Author Share Posted January 22, 2010 I have put as you have said above and still is passing empty, or id =0 Quote Link to comment https://forums.phpfreaks.com/topic/189395-i-am-having-an-undefined-variable/#findComment-999746 Share on other sites More sharing options...
btherl Posted January 22, 2010 Share Posted January 22, 2010 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'. '®ister='. $_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? Quote Link to comment https://forums.phpfreaks.com/topic/189395-i-am-having-an-undefined-variable/#findComment-999754 Share on other sites More sharing options...
co.ador Posted January 22, 2010 Author Share Posted January 22, 2010 i have just verified again and line 247 is <p> <a href=<?php echo "cart.php?action=remove_item&ids=" . $row["id"] .'&qty=1'. '®ister='. $_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. Quote Link to comment https://forums.phpfreaks.com/topic/189395-i-am-having-an-undefined-variable/#findComment-999762 Share on other sites More sharing options...
btherl Posted January 24, 2010 Share Posted January 24, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/189395-i-am-having-an-undefined-variable/#findComment-1000707 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.