Jump to content

Empty function no longer detects an empty select list


Phphineas

Recommended Posts

I have some very simple code in a PHP web application that is something like this:

 

<select name="my_select" id="my_select" value="">

  <option value=""></option>

  <option value="1">Pass</option>

  <option value="0">Fail</option>

</select>

if (empty($_POST['myselect'])) {

  // if no select value is chosen, field value = current value

  $field_value = $_REQUEST['field_value'];

} else {

  // else set field value to select value

  $field_value = $_POST['select_value'];

}

$sql = "update my table

        set field_value = :field_value";

 

If the user chooses a value from the select list, that value is used to update a table. If the select value is empty, the field value stays as is. A button triggers the update query.

This has been working fine until today. Now, if the user selects a value, the field is updated to 1 / Pass. But if the button is clicked again and no value is chosen, the field is automatically updated to the opposite value, 0 / Fail.

I can't figure out why this is suddenly happening after it worked correctly for so long. Any input you may have would be appreciated.

Link to comment
Share on other sites

Where does $_REQUEST have to do with this?  You are apparently processing a POST method on a form so stick with that!

And what do the fields "field_value" and "select_value" have to do with this topic? You are only showing us one form field and it is named "my_select".

And you are trying to access a field named "myselect" but you are not showing us that field in your code example either.

And - when one posts code here you should use the <> symbol at the top of you window to post the code into.  Makes for nicer reading.  And leave out the extra blank lines too if you can.

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.