kristofferlc Posted July 24, 2009 Share Posted July 24, 2009 Hi everyone, i've been working on a script where i have to call some defreind $_POST variables, names after ID´s in a database, verry much like in this topic: http://www.phpfreaks.com/forums/index.php/topic,261404.0.html I belive i'm calling the functions properly, and i know my query works, so i dont realy know why my server cant call the $_POST variables... My code looks somewhat like this: while ($row_categories = mysql_fetch_assoc($categories)) { $tmp = $row_categories['id']; if(isset($_POST["$tmp"])) { echo $_POST["$tmp"]; } } This isnt the only thing that wont work, i've tried with a normal while loop where i use $i = 0; and $i++;... So, my big problem is that the server returns "false" on the isset($_POST["$tmp"]); function... Does anyone have an idea why?... Quote Link to comment https://forums.phpfreaks.com/topic/167202-solved-problem-calling-_posti/ Share on other sites More sharing options...
Philip Posted July 24, 2009 Share Posted July 24, 2009 Well, you technically don't need the quotes around it if its just a variable. That won't cause the problem... just a side thing. Are you sure the database values are the same as the form names - Echo them to see! Try running the following, it will give you all your data names and will show you why they aren't matching up: while ($row_categories = mysql_fetch_assoc($categories)) { $tmp = $row_categories['id']; if(isset($_POST[$tmp])) { echo $_POST[$tmp],'<br>'; } else { echo 'Failed on: ',$tmp,'<br>'; } } echo '<pre>'; print_r($_POST); echo '</pre>'; Quote Link to comment https://forums.phpfreaks.com/topic/167202-solved-problem-calling-_posti/#findComment-881583 Share on other sites More sharing options...
kristofferlc Posted July 24, 2009 Author Share Posted July 24, 2009 Yes, the database values are the same as called, and while i tried echoing them with your script it didnt reyurn anything... It doesnt even return anything with this more simple loop: (Checkbox's with the name 1,2,3,4 and 5 are being used to check this, same value as name, if that matters....) $i = 0; while($i<=5) { $i++; if(isset($_POST[$i])) { echo $i; } } I get NOTHING in return from any of them... :S Quote Link to comment https://forums.phpfreaks.com/topic/167202-solved-problem-calling-_posti/#findComment-881591 Share on other sites More sharing options...
Philip Posted July 24, 2009 Share Posted July 24, 2009 while i tried echoing them with your script it didnt reyurn anything... You got nothing at all? You should have at least gotten Array ( ) Quote Link to comment https://forums.phpfreaks.com/topic/167202-solved-problem-calling-_posti/#findComment-881595 Share on other sites More sharing options...
kristofferlc Posted July 24, 2009 Author Share Posted July 24, 2009 Okay, i've got something now... I tried with the simple loop, and ran your code trough it: if($_POST) { $i=1; while($i<=5) { if(isset($_POST[$i])) { echo $_POST[$i]; } else { echo "Failed on $i<br />"; } $i++; } echo '<pre>'; print_r($_POST); echo '</pre>'; } And i got this out of it (marking box 2 and 3): Failed on 1 2 3 Failed on 4 Failed on 5 Array ( [2] => 2 [3] => 3 [button] => Submit ) I'll work a bit on the database called array, hang on. (And thanks so far) Quote Link to comment https://forums.phpfreaks.com/topic/167202-solved-problem-calling-_posti/#findComment-881598 Share on other sites More sharing options...
Philip Posted July 24, 2009 Share Posted July 24, 2009 Okay, good start Quote Link to comment https://forums.phpfreaks.com/topic/167202-solved-problem-calling-_posti/#findComment-881599 Share on other sites More sharing options...
kristofferlc Posted July 24, 2009 Author Share Posted July 24, 2009 Okay, getting something now, but still not a solution. Now i call the loop like this: do { $tmp = $row_butikker['ID']; if(isset($_POST[$tmp])) { echo $_POST[$tmp].'<br>'; } else { echo 'Failed on: '.$tmp.'<br>'; } echo $row_butikker['ID'].'<br><br>'; } while ($row_butikker = mysql_fetch_assoc($butikker)); echo '<pre>'; print_r($_POST); echo '</pre>'; And gets this in return: Failed on: Array ( [8] => 8 [6] => 6 ) So i'm guessing something's wrong with my call of the loop, since it fails to show the $tmp value anyhow... I call the database the same way in the form script and the loop script... (And database data is static as it is now, i'm only running in test stages.) Quote Link to comment https://forums.phpfreaks.com/topic/167202-solved-problem-calling-_posti/#findComment-881606 Share on other sites More sharing options...
Philip Posted July 24, 2009 Share Posted July 24, 2009 Make sure this is at the top: error_reporting(E_ALL); ini_set('display_errors', TRUE); I have a sneaky suspicion it has to do with the column name in your database. First, you used 'id' now 'ID' - what is it in the db? Quote Link to comment https://forums.phpfreaks.com/topic/167202-solved-problem-calling-_posti/#findComment-881610 Share on other sites More sharing options...
kristofferlc Posted July 24, 2009 Author Share Posted July 24, 2009 I know i made that error, ID is the right one to use, but i still get nothing while trying to make the loop... The code you just gave didnt return anything... But i think i'm calling the query in a wrong way, i cant make it repeat the ID value... Hold on please. A litle more testing, i think i'm on a clue now... And again thanks for giving your self time to help me with this. Quote Link to comment https://forums.phpfreaks.com/topic/167202-solved-problem-calling-_posti/#findComment-881614 Share on other sites More sharing options...
kristofferlc Posted July 24, 2009 Author Share Posted July 24, 2009 FINALY!! I made it work. In my query i was using a session identify what ID's to get, and i had not included the session_start() function. :S Sorry for making this stupid error, and thanks alot for all the help i got from you KingPhilip. Quote Link to comment https://forums.phpfreaks.com/topic/167202-solved-problem-calling-_posti/#findComment-881616 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.