Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

problems with arrays and checkboxes/radio buttons

pdunnpdunn Posts: 63Member
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

Comments

  • IDKIDK Posts: 1,784Member
    : 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)
  • pdunnpdunn Posts: 63Member
    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)
    :

  • IDKIDK Posts: 1,784Member
    : 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.
  • pdunnpdunn Posts: 63Member
    Here's some of the code that the person wanted.

    The first part makes the form

    ...

    echo "";
    echo "";

    $guest_number_temp = $guest_number;

    while($guest_number >= 1)
    {

    echo "";

    echo "";
    echo "";

    echo "";

    echo "";

    echo "";
    ...

    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 "Please inform us if guest number $guest_number_index needs a hotel room.";
    $null = true;

    }

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

    echo "Please inform us of guest number $guest_number_index first name.";
    $null = true;

    }

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

    echo "Please inform us of guest number $guest_number_index last name.";
    $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.
    :
    ";
    echo "Please enter in the person's first name:
      

    ";

    echo "Please enter in the person's last name:
      


    ";
    echo "Does this person needs a hotel room?:
      
    Yes";

    echo "No";

    echo "
  • IDKIDK Posts: 1,784Member
    [b][red]This message was edited by IDK at 2006-9-20 10:29:9[/red][/b][hr]
    : Here's some of the code that the person wanted.
    :
    : The first part makes the form
    :
    : ...
    :
    [code]
    : echo "";
    : echo "";
    :
    : $guest_number_temp = $guest_number;
    :
    : while($guest_number >= 1)
    : {
    :
    : echo "";
    :
    : echo "";
    : echo "";
    :
    : echo "";
    :
    : echo "";
    :
    : echo "";
    : ...
    :
    [/code]
    : The second part is located inside of my checker for null values
    [code]
    :
    : ...
    : $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 "Please inform us if guest number $guest_number_index needs a hotel room.";
    : $null = true;
    :
    : }
    :
    : if(
    : !isset($guest_firstname[$guest_number])
    : ||
    : ('' == $guest_firstname[$guest_number]))
    : {
    :
    : echo "Please inform us of guest number $guest_number_index first name.";
    : $null = true;
    :
    : }
    :
    : if(
    : !isset($guest_lastname[$guest_number])
    : ||
    : ('' == $guest_lastname[$guest_number]))
    : {
    :
    : echo "Please inform us of guest number $guest_number_index last name.";
    : $null = true;
    :
    : }
    [/code]

    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.
    ";
    : echo "Please enter in the person's first name:
    :   

    :
    ";
    :
    : echo "Please enter in the person's last name:
    :   

    :
    ";
    : echo "Does this person needs a hotel room?:
      
    : Yes";
    :
    : echo "No";
    :
    : echo "
Sign In or Register to comment.