PHP

Moderators: None (Apply to moderate this forum)
Number of threads: 1848
Number of posts: 5016

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
problems with arrays and checkboxes/radio buttons Posted by pdunn on 20 Sept 2006 at 6:57 AM
Hello, I am using a form to get information and I need to loop through a certain amount of times based on the previous form. I got that done, but if no information in typed in the second form and I try to verify. I get notices that say that "Notice: Uninitialized string offset: 2 in /home/web/test.php on line 768". That is because no information was written in the array. I get this message when using !isset(array($loop)) and I tried empty() (but that's nearly {less than} the same). array($loop) of uninitialized value will always give me that Notice. I don't have the power to change if the Notices will show or not, so I need to full fix this. I have no solution to this. Please advise.

Thank you,

pdunn

Report
Re: problems with arrays and checkboxes/radio buttons Posted by IDK on 20 Sept 2006 at 8:12 AM
: Hello, I am using a form to get information and I need to loop through a certain amount of times based on the previous form. I got that done, but if no information in typed in the second form and I try to verify. I get notices that say that "Notice: Uninitialized string offset: 2 in /home/web/test.php on line 768". That is because no information was written in the array. I get this message when using !isset(array($loop)) and I tried empty() (but that's nearly {less than} the same). array($loop) of uninitialized value will always give me that Notice. I don't have the power to change if the Notices will show or not, so I need to full fix this. I have no solution to this. Please advise.
:
: Thank you,
:
: pdunn
:
:

Can't you just pass a bool variable?
(I don't remeber if php has bools, but the principle is the same)
Report
Re: problems with arrays and checkboxes/radio buttons Posted by pdunn on 20 Sept 2006 at 9:06 AM
Either I don't understand you or you don't understand me.
I will further the information. I need to get a "Yes" or a "No" from the user. I will use radio buttons just like in the rest of the site. Since these button values depends on the amount of people from the previous form, I have to use an array as the variable.

I did made a new discovery. Regardless how many items the array is SUPPOSED to have, if at least one is filled in, there is no error. What I meant by SUPPOSED is that if the amount of people is 20, the array should be of size 20. However, if the user only fills in the information for at least 1 person, then there will not be a notice about
uninitialization string and my error checking works with isset(). However, if none is set, then the problem occurs with isset(), empty(), etc. Any call to array(index) will result in an error since nothing is inside of the array. But if one thing is inside of the error, then the index is simply not set. So, how do I see if anything is in an array? Without printing it out, but checking

count(), this did not work, it gives the value of 1. Does this help you to understand my situation?

Thank you,

pdunn


: : Hello, I am using a form to get information and I need to loop through a certain amount of times based on the previous form. I got that done, but if no information in typed in the second form and I try to verify. I get notices that say that "Notice: Uninitialized string offset: 2 in /home/web/test.php on line 768". That is because no information was written in the array. I get this message when using !isset(array($loop)) and I tried empty() (but that's nearly {less than} the same). array($loop) of uninitialized value will always give me that Notice. I don't have the power to change if the Notices will show or not, so I need to full fix this. I have no solution to this. Please advise.
: :
: : Thank you,
: :
: : pdunn
: :
: :
:
: Can't you just pass a bool variable?
: (I don't remeber if php has bools, but the principle is the same)
:

Report
Re: problems with arrays and checkboxes/radio buttons Posted by IDK on 20 Sept 2006 at 9:51 AM
: Either I don't understand you or you don't understand me.
: I will further the information. I need to get a "Yes" or a "No" from the user. I will use radio buttons just like in the rest of the site. Since these button values depends on the amount of people from the previous form, I have to use an array as the variable.
:
: I did made a new discovery. Regardless how many items the array is SUPPOSED to have, if at least one is filled in, there is no error. What I meant by SUPPOSED is that if the amount of people is 20, the array should be of size 20. However, if the user only fills in the information for at least 1 person, then there will not be a notice about
: uninitialization string and my error checking works with isset(). However, if none is set, then the problem occurs with isset(), empty(), etc. Any call to array(index) will result in an error since nothing is inside of the array. But if one thing is inside of the error, then the index is simply not set. So, how do I see if anything is in an array? Without printing it out, but checking
:
: count(), this did not work, it gives the value of 1. Does this help you to understand my situation?
:
: Thank you,
:
: pdunn
:
Yeah, sorry, I just skimmed(don't know if that's a word...) through your post. I'm to tired...

OK, your prob seems to be some langauge thingy, and as I don't know php very well I can't help very much.

But I'm still curious, post your code.
Report
Re: problems with arrays and checkboxes/radio buttons Posted by pdunn on 20 Sept 2006 at 10:09 AM
Here's some of the code that the person wanted.

The first part makes the form

...

echo "<form name=\"form\" action=\"people.php\" method=\"post\">";
echo "<table>";

$guest_number_temp = $guest_number;

while($guest_number >= 1)
{

echo "<tr><td colspan = 2>";
echo "Please enter in the person's first name:
&nbsp;&nbsp;</td></tr>";

echo "<tr><td>
<input type=text name=guest_firstname[$guest_number] ></td></tr>";
echo "<tr><td colspan = 2>";

echo "Please enter in the person's last name:
&nbsp;&nbsp;</td></tr>";

echo "<tr><td>
<input type=text name=guest_lastname[$guest_number] ></td></tr>";

echo "<tr><td colspan = 2><br>";
echo "Does this person needs a hotel room?: </td></tr>";

echo "<tr><td>&nbsp;&nbsp;
<input type=radio name=guest_hotel[$guest_number] value=\"yes\">Yes";

echo "<input type=radio name=guest_hotel[$guest_number] value=\"no\">No";

echo "</td></tr>";
...

The second part is located inside of my checker for null values

...
$null = false;
global $guest_number;
$guest_number_holder = $guest_number;

while($guest_number >= 1)
{

//the guest number index is the position in terms of what the user sees and not the computer

$guest_number_index = $guest_number_holder - $guest_number + 1;

if(
!isset($guest_hotel[$guest_number])
||
('' == $guest_hotel[$guest_number]))
{

echo "<div id=red-asterk>Please inform us if guest number $guest_number_index needs a hotel room.</div>";
$null = true;

}

if(
!isset($guest_firstname[$guest_number])
||
('' == $guest_firstname[$guest_number]))
{

echo "<div id=red-asterk>Please inform us of guest number $guest_number_index first name.</div>";
$null = true;

}

if(
!isset($guest_lastname[$guest_number])
||
('' == $guest_lastname[$guest_number]))
{

echo "<div id=red-asterk>Please inform us of guest number $guest_number_index last name.</div>";
$null = true;

}
...




: : Either I don't understand you or you don't understand me.
: : I will further the information. I need to get a "Yes" or a "No" from the user. I will use radio buttons just like in the rest of the site. Since these button values depends on the amount of people from the previous form, I have to use an array as the variable.
: :
: : I did made a new discovery. Regardless how many items the array is SUPPOSED to have, if at least one is filled in, there is no error. What I meant by SUPPOSED is that if the amount of people is 20, the array should be of size 20. However, if the user only fills in the information for at least 1 person, then there will not be a notice about
: : uninitialization string and my error checking works with isset(). However, if none is set, then the problem occurs with isset(), empty(), etc. Any call to array(index) will result in an error since nothing is inside of the array. But if one thing is inside of the error, then the index is simply not set. So, how do I see if anything is in an array? Without printing it out, but checking
: :
: : count(), this did not work, it gives the value of 1. Does this help you to understand my situation?
: :
: : Thank you,
: :
: : pdunn
: :
: Yeah, sorry, I just skimmed(don't know if that's a word...) through your post. I'm to tired...
:
: OK, your prob seems to be some langauge thingy, and as I don't know php very well I can't help very much.
:
: But I'm still curious, post your code.
:
Report
Re: problems with arrays and checkboxes/radio buttons Posted by IDK on 20 Sept 2006 at 10:22 AM
This message was edited by IDK at 2006-9-20 10:29:9

: Here's some of the code that the person wanted.
:
: The first part makes the form
:
: ...
:
: echo "<form name=\"form\" action=\"people.php\" method=\"post\">";
: echo "<table>";
: 
: $guest_number_temp = $guest_number;
: 
: while($guest_number >= 1)
: {
: 
: echo "<tr><td colspan = 2>";
: echo "Please enter in the person's first name: 
: &nbsp;&nbsp;</td></tr>";
: 
: echo "<tr><td>
: <input type=text name=guest_firstname[$guest_number] ></td></tr>";
: echo "<tr><td colspan = 2>";
: 
: echo "Please enter in the person's last name:
: &nbsp;&nbsp;</td></tr>";
: 
: echo "<tr><td>
: <input type=text name=guest_lastname[$guest_number] ></td></tr>";
: 
: echo "<tr><td colspan = 2>";
: echo "Does this person needs a hotel room?: </td></tr>";
: 
: echo "<tr><td>&nbsp;&nbsp;
: <input type=radio name=guest_hotel[$guest_number] value=\"yes\">Yes";
: 
: echo "<input type=radio name=guest_hotel[$guest_number] value=\"no\">No";
: 
: echo "</td></tr>";
: ...
: 

: The second part is located inside of my checker for null values
: 
: ...
: $null = false;
: global $guest_number;
: $guest_number_holder = $guest_number;
: 	
: while($guest_number >= 1)
: {
: 
: //the guest number index is the position in terms of what the user sees and not the computer
: 
: $guest_number_index = $guest_number_holder - $guest_number + 1;
: 
: if(
: !isset($guest_hotel[$guest_number]) 
: ||
: ('' == $guest_hotel[$guest_number]))
: {
: 
: echo "<div id=red-asterk>Please inform us if guest number $guest_number_index needs a hotel room.</div>";
: $null = true;
: 
: }
: 
: if(
: !isset($guest_firstname[$guest_number]) 
: ||
: ('' == $guest_firstname[$guest_number]))
: {
: 
: echo "<div id=red-asterk>Please inform us of guest number $guest_number_index first name.</div>";
: $null = true;
: 
: }
: 
: if(
: !isset($guest_lastname[$guest_number])  
: || 
: ('' == $guest_lastname[$guest_number]))
: {
: 
: echo "<div id=red-asterk>Please inform us of guest number $guest_number_index last name.</div>";
: $null = true;
: 
: }


Code tags make me happy

But they didn't help much.

I don't know how arrays are passed, are you sure it's the right way?
Isn't it something with _$ or something.
Is it even possible to pass arrays?
If I recall it is...

I have really no idea.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.