rationalrabbit Posted May 18, 2007 Share Posted May 18, 2007 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. :? Link to comment https://forums.phpfreaks.com/topic/52000-solved-using-onchange-with-select-php-mysql/ Share on other sites More sharing options...
rationalrabbit Posted May 18, 2007 Author Share Posted May 18, 2007 Hah! Should have been '$VacStatus' instead of $VacStatus in the Query (needed quotes) Link to comment https://forums.phpfreaks.com/topic/52000-solved-using-onchange-with-select-php-mysql/#findComment-256297 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.