Jump to content

Recommended Posts

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?... :wtf:

Link to comment
https://forums.phpfreaks.com/topic/167202-solved-problem-calling-_posti/
Share on other sites

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>';

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

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)

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.)

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. :)

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.