Jump to content

[SOLVED] Problem trying to read multiple post vars


Sulman

Recommended Posts

HI

I'm having problems extracting values from post vars.

 

The post array looks like this (print_r($_POST)):

Array ( [response-812] => Y-812 [notes-812] => [FixtureID-812] => 812 [response-814] => choose-814 [notes-814] => [FixtureID-814] => 814 [response-818] => choose-818 [notes-818] => [FixtureID-818] => 818 [response-819] => choose-819 [notes-819] => [FixtureID-819] => 819 [response-1522] => choose-1522 [notes-1522] => [FixtureID-1522] => 1522 [response-1524] => choose-1524 [notes-1524] => [FixtureID-1524] => 1524 [response-1527] => choose-1527 [notes-1527] => [FixtureID-1527] => 1527 [response-1528] => choose-1528 [notes-1528] => [FixtureID-1528] => 1528 )

(the first select has been chosen and no others)

 

I am trying to loop through the array and find any that begin with Y, P or N (these are select boxes that are distinguished between by applying the fixtireID to the option). E.g.:

 

<select name="response-812">
<option value="choose-812">Choose</option>
<option value="Y-812">Yes</option>
<option value="P-812">Provisionally</option>
<option value="N-812">No - Reject</option>

</select>

<select name="response-814">
<option value="choose-814">Choose</option>
<option value="Y-814">Yes</option>
<option value="P-814">Provisionally</option>
<option value="N-814">No - Reject</option>
</select>

(there are also some different post vars)

 

But when I use the following code to check each var it doesn't seem to be working:

 

foreach($_POST as $p)
{
$pos=strpos($p, "N");
$pos=strpos($p, "Y");
$pos=strpos($p, "P");
echo "pos=".$pos." for post var [".$p."]<br> ";
}

 

And just gives me this:

pos= for post var [Y-812]

pos= for post var []

pos= for post var [812]

pos= for post var [choose-814]

pos= for post var []

pos= for post var [814]

pos= for post var [choose-818]

pos= for post var []

pos= for post var [818]

pos= for post var [choose-819]

pos= for post var []

pos= for post var [819]

pos= for post var [choose-1522]

pos= for post var []

pos= for post var [1522]

pos= for post var [choose-1524]

pos= for post var []

pos= for post var [1524]

pos= for post var [choose-1527]

pos= for post var []

pos= for post var [1527]

pos= for post var [choose-1528]

pos= for post var []

pos= for post var [1528]

 

Where I would expect this:

 

pos=0 for post var [Y-812]

pos= for post var []

pos= for post var [812]

pos= for post var [choose-814]

pos= for post var []

pos= for post var [814]

pos= for post var [choose-818]

pos= for post var []

pos= for post var [818]

pos= for post var [choose-819]

pos= for post var []

pos= for post var [819]

pos= for post var [choose-1522]

pos= for post var []

pos= for post var [1522]

pos= for post var [choose-1524]

pos= for post var []

pos= for post var [1524]

pos= for post var [choose-1527]

pos= for post var []

pos= for post var [1527]

pos= for post var [choose-1528]

pos= for post var []

pos= for post var [1528]

 

Can anyone see what I am doing wrong? (or even recommend a better way?)

 

Thanks

 

 

Link to comment
Share on other sites

Thanks for your help.

 

But

foreach($_POST as $p)
{
$pos= @array_search('Y', $p);
$pos= @array_search('P', $p);
$pos= @array_search('N', $p);

//echo "pos=".$pos."<br>";
echo "pos=".$pos." for post var [".$p."]<br> ";
}

just gives me

pos= for post var [Y-812]

pos= for post var []

pos= for post var [812]

pos= for post var [choose-814]

pos= for post var []

pos= for post var [814]

pos= for post var [choose-818]

pos= for post var []

pos= for post var [818]

pos= for post var [choose-819]

pos= for post var []

pos= for post var [819]

pos= for post var [choose-1522]

pos= for post var []

pos= for post var [1522]

pos= for post var [choose-1524]

pos= for post var []

pos= for post var [1524]

pos= for post var [choose-1527]

pos= for post var []

pos= for post var [1527]

pos= for post var [choose-1528]

pos= for post var []

pos= for post var [1528]

 

Any idea why?

Link to comment
Share on other sites

Thanks for your help so far. But that doesn't work either. Just gives me the same results as above.

 

(ignoring the multiple errors: Warning: array_search() [function.array-search]: Wrong datatype for second argument in c:\Inetpub\wwwroot\club\handles\handle-update-fixtures.php on line n)

 

??

Link to comment
Share on other sites

Well my ultimate goal isn't to output anything. I'm just outputing at the moment for debug purposes.

 

The idea is to loop through the post array and find any of the selection boxes that do not contain "choose" (as this is the default option and therefore means no optionhas been selected). Once I have found one that contains either a Y, P or N I can then extract the fixtureID off the end of it and therefore will know what has been chosen for each fixture.

 

Hope that makes sense  ???

 

Thanks!

 

[edit] The errors are supressed as I keep getting "Warning: array_search() [function.array-search]: Wrong datatype for second argument in c:\Inetpub\wwwroot\club\handles\handle-update-fixtures.php on line n"

Link to comment
Share on other sites

thanks.

 

I have looked at array_search but I don't think it's really what I need.

 

As per my first post, I can loop through the $_POST array ok, it's just extracting the Y, N or P bits that doesn't seem to be working?

 

Thanks for your time.

Link to comment
Share on other sites

this code is a simple debug:

foreach($_POST as $p)
{
echo "checking ".$p." for Y, N or P---";

$pos=strpos($p, "N");
$pos=strpos($p, "Y");
$pos=strpos($p, "P");

echo "pos= ".$pos."<br>";
}

 

and outputs this:

checking Y-812 for Y, N or P---pos=

checking for Y, N or P---pos=

checking 812 for Y, N or P---pos=

checking choose-814 for Y, N or P---pos=

checking for Y, N or P---pos=

checking 814 for Y, N or P---pos=

checking choose-818 for Y, N or P---pos=

checking for Y, N or P---pos=

checking 818 for Y, N or P---pos=

checking choose-819 for Y, N or P---pos=

checking for Y, N or P---pos=

checking 819 for Y, N or P---pos=

checking choose-1522 for Y, N or P---pos=

checking for Y, N or P---pos=

checking 1522 for Y, N or P---pos=

checking choose-1524 for Y, N or P---pos=

checking for Y, N or P---pos=

checking 1524 for Y, N or P---pos=

checking choose-1527 for Y, N or P---pos=

checking for Y, N or P---pos=

checking 1527 for Y, N or P---pos=

checking choose-1528 for Y, N or P---pos=

checking for Y, N or P---pos=

checking 1528 for Y, N or P---pos=

 

Surely the highlited line should have a pos?

 

Mightily confused!

Link to comment
Share on other sites

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.