JudgementDay Posted February 6, 2012 Share Posted February 6, 2012 I am getting Use of undefined constant id - assumed 'id' with this: $query = "SELECT * FROM products WHERE id = ".mysql_real_escape_string($_POST[id]).""; That seems pretty bull shit to me. Is this a bug in PHP? Quote Link to comment https://forums.phpfreaks.com/topic/256507-bug-in-php-pretty-certain-it-is/ Share on other sites More sharing options...
PFMaBiSmAd Posted February 6, 2012 Share Posted February 6, 2012 Associative array index names are strings and need to be quoted, the reason being is that you could be using defined constants to provide the actual values and the syntax needs to support both methods. Use quotes around index names that are literal strings (the extra code that php executes behind the scenes in the error response code every time it finds an unquoted array index name is a killer.) Quote Link to comment https://forums.phpfreaks.com/topic/256507-bug-in-php-pretty-certain-it-is/#findComment-1314926 Share on other sites More sharing options...
JudgementDay Posted February 6, 2012 Author Share Posted February 6, 2012 Wow! I don't have a clue what you are talking about. Do you mean that I should just do: $id = 1; $query = "SELECT * FROM products WHERE id = ".mysql_real_escape_string($_POST[id]).""; Quote Link to comment https://forums.phpfreaks.com/topic/256507-bug-in-php-pretty-certain-it-is/#findComment-1314927 Share on other sites More sharing options...
digibucc Posted February 6, 2012 Share Posted February 6, 2012 i think they mean this: <?php $id = 1; $query = "SELECT * FROM products WHERE id = mysql_real_escape_string($_POST['id'])"; //or even $query = 'SELECT * FROM products WHERE id = '. mysql_real_escape_string($_POST['id']); ?> the index is the value key in an array you are trying to pull,in this case "id" from the $_POST array RIGHT = $_POST['id'] WRONG = $_POST[id] id - assumed 'id' says it all, it expected quotes around the word Quote Link to comment https://forums.phpfreaks.com/topic/256507-bug-in-php-pretty-certain-it-is/#findComment-1314930 Share on other sites More sharing options...
JudgementDay Posted February 6, 2012 Author Share Posted February 6, 2012 Yes, you are correct about the quotes needing to be $_POST['id']. Its funny how the mind works. I didn't even see it! I saw $_POST[id] as a whole. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/256507-bug-in-php-pretty-certain-it-is/#findComment-1314937 Share on other sites More sharing options...
digibucc Posted February 6, 2012 Share Posted February 6, 2012 Its funny how the mind works. I didn't even see it! I saw $_POST[id] as a whole. Thanks. it is isn't it! I scan spend hours looking at code i know is right, and then a cursory glance the next day shows me a hundred problems i missed. Quote Link to comment https://forums.phpfreaks.com/topic/256507-bug-in-php-pretty-certain-it-is/#findComment-1314942 Share on other sites More sharing options...
JudgementDay Posted February 6, 2012 Author Share Posted February 6, 2012 Hah so true! One thing I have learn't with programming (and one reason I don't stress) is that sleep solves your problems. Quote Link to comment https://forums.phpfreaks.com/topic/256507-bug-in-php-pretty-certain-it-is/#findComment-1315026 Share on other sites More sharing options...
spiderwell Posted February 6, 2012 Share Posted February 6, 2012 thats why proof reading is a big thing, its often easier to spot mistakes in someone else's text than your own. Quote Link to comment https://forums.phpfreaks.com/topic/256507-bug-in-php-pretty-certain-it-is/#findComment-1315037 Share on other sites More sharing options...
sql-lover Posted February 6, 2012 Share Posted February 6, 2012 Its funny how the mind works. I didn't even see it! I saw $_POST[id] as a whole. Thanks. it is isn't it! I scan spend hours looking at code i know is right, and then a cursory glance the next day shows me a hundred problems i missed. . That's so true! Quote Link to comment https://forums.phpfreaks.com/topic/256507-bug-in-php-pretty-certain-it-is/#findComment-1315079 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.