Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jun 2005
    Thanked 0 Times in 0 Posts

    Question Using Select OnChange and Update Database

    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>

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Saskatoon, Saskatchewan
    Thanked 2,662 Times in 2,631 Posts
    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.
    Last edited by Fou-Lu; 06-28-2005 at 03:34 AM.


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts