View Full Version : Using Select OnChange and Update Database

06-28-2005, 02:27 AM
I am having a little bit of a problem updating the database with the new value from the drop down box. For some reason it isn't receiving the value.

$user = mysql_fetch_array(mysql_query("SELECT online,status,username,theme FROM $tab[user] WHERE id='$id';"));

mysql_query("UPDATE $tab[user] SET theme='$gametheme' WHERE id='$id'");
$user = mysql_fetch_array(mysql_query("SELECT online,status,username,theme FROM $tab[user] WHERE id='$id';"));

<form method="post" action="" name="usertheme">
<select name="gametheme" onChange="document.usertheme.submit()">
<option value="0" <? if($user[3]==0){echo "selected";} ?>>blue</option>
<option value="1" <? if($user[3]==1){echo "selected";} ?>>purple</option>
<option value="2" <? if($user[3]==2){echo "selected";} ?>>red</option>
<option value="3" <? if($user[3]==3){echo "selected";} ?>>green</option>
<option value="4" <? if($user[3]==4){echo "selected";} ?>>dark blue</option>
<option value="5" <? if($user[3]==5){echo "selected";} ?>>orange</option>

06-28-2005, 03:31 AM
If its being submitted correctly back, the problem is with your globals, they are not registered. Don't register them though, its better that they are off:
Anywhere you have $gametheme, change it to $_POST['gametheme'], with the exception of the query and form, use mysql_real_escape_string($_POST['gametheme']) instead for the query, and the form is just fine as is.
Also, I suggest adding a submit button as well for users whom do not use javascript.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum