Jump to content

[SOLVED] Using onChange with select, PHP, Mysql


rationalrabbit

Recommended Posts

MySQL v4.1.21-standard

PHP v4.4.4

 

Occasionally, this works. Most of the time it doesn't. This may be more of a MySQL problem than PHP - I don't know for sure.

I have a drop-down box with two selections; ON and OFF that I store in a field of an SQL table that only holds one record. The idea is that the user makes a selection, the database record is updated, and that selection becomes the default. Except on a rare occasion, the database is not updating. Here is the code:

In the HTML Head section:

if (isset($_POST['VacStatus']))
{
   $query="UPDATE ColumnData SET VacOption = $VacStatus WHERE RecNo = 1";
   mysql_query($query);
}

Then the database is queried and field values are stored in an array called "PageVars".

Then the DropDown:

<form style="margin-top:0;" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
   <select name="VacStatus" onChange="submit()">
      <option <? if($pageVars[VacOption] == "ON"){echo "selected ";} ?> value="ON">Active</option>
      <option <? if($PageVars[VacOption] == "OFF"){echo "selected ";} ?> value="OFF">Inactive</option>
   </select>
</form>

 

Seems to me this should work. :? 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.