Jump to content


Photo

Having problems updating using drop-down menu


  • Please log in to reply
4 replies to this topic

#1 massive

massive
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 28 February 2006 - 06:15 AM

Hi guyz, i have trouble in updating my data using drop-down menus...im trying to upgrade a subscribers ServiceType....but its seems i have so problems... i don't know whats wrong with it here is a part of my script:

-------script for querying---------

<?  

    if((!isset($_GET['id']) || trim($_GET['id']) == ''))
        {
            die('Missing record ID!');
        }
 
    $connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die('Unable to connect!');
    mysql_select_db(DB_NAME) or die('Unable to select database');
    $id = $_GET['id'];
    $q = "SELECT username, ServiceType FROM subscription WHERE username = '$id'";
    $w = mysql_query($q) or die("Error in query: $q. " . mysql_error());
  
    if(isset($_POST['change'])) 
    {
    
        $query  = "UPDATE subscription SET ServiceType = '" . $_POST['service'] . "' WHERE username = '$id'";
    $result = mysql_query($query) or die("Error in query: $query. " . mysql_error());
  
  }
  if($result)
  {
      header("Location: updatesuccess.php");
  }
?>    


-----html drop down menu declaration----------
<select name="service">
          <option>-----------</option>
          <option value="NR5">NR5</option>
          <option value="NR10">NR10</option>
          <option value="NR15">NR15</option>
          <option value="NR20">NR20</option>
          <option value="NR25">NR25</option>
          <option value="NR30">NR30</option>
          <option value="NR40">NR40</option>
          <option value="NR50">NR50</option>
          <option value="NR60">NR60</option>
          <option value="NR80">NR80</option>
          <option value="NR100">NR100</option>
          <option value="NR120">NR120</option>
          <option value="R10">R10</option>
          <option value="R20">R20</option>
          <option value="R30">R30</option>
          <option value="R40">R40</option>
          <option value="R50">R50</option>
          <option value="R60">R60</option>
          <option value="R80">R80</option>
          <option value="R100">R100</option>
          <option value="R120">R120</option>
        </select>


------here is the submit button declaration--------
<input type="submit" name="change"  value="Upgrade">

hmmm i'm quite puzzled...wondering where did i go wrong pls help...thank you

#2 soccer022483

soccer022483
  • Members
  • Pip
  • Newbie
  • 6 posts

Posted 28 February 2006 - 07:05 PM

Try changing your form to method = 'GET' and make sure your variables are in the address bar correctly.

#3 XenoPhage

XenoPhage
  • Members
  • PipPipPip
  • Advanced Member
  • 99 posts

Posted 28 February 2006 - 08:55 PM

Try printing the query to make sure it's what you're expecting.
--
[a href=\"http://blog.godshell.com\" target=\"_blank\"]XenoPhage[/a]
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Something mysterious is formed, born in the silent void. Waiting alone and unmoving, it is at once still and yet in constant motion. It is the source of all programs. I do not know its name, so I will call it the Tao of Programming.[/quote]

#4 massive

massive
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 01 March 2006 - 03:41 PM

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]

Try changing your form to method = 'GET' and make sure your variables are in the address bar correctly.

[/quote]

oh yeah i have'nt tried that ^_^ and about the address bar the variables are shown fine ^^...but the thing is everytime i press the button


it says:



"Missing record ID"

but my address bar where shown like this for example:(i know you got my point ^_^)

somelink.php?id=chicken



Step 1

1. source.php <-----where the variables came from

Step 2
2. geting.php?id=chicken <------where the variables were transfered and data chickens information was displayed here...yet when i press the button in the geting.php page....click....then "Missing record ID" (T_T)
come to think of it the variables where shown in both the address bar and at the status bar

im puzzled pls help tnx...

#5 Snip

Snip
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 01 March 2006 - 04:07 PM

Here is what I've come up with.
//$user = $_POST['user']
             $url = $_SERVER["PHP_SELF"];
                
                echo "<form method=\"get\" name=\"userselection\" action=\"$url\">";
                echo '<select size="1" name="user" onchange="forms[\'userselection\'].submit()"> ';
                while($i<$num){
                      /* Output combo box */
                      $value=mysql_result($result,$i);
                    echo("<option value=");
                    echo( $value );
                         if(strtolower($user)==strtolower($value)){
                           echo " selected=true";
                    }
                    echo(">");
                    echo( $value );
                    echo("</option>");
                    $i++;
                }
                echo("</select>");
                echo '</form>';

When you select a different item in the combobox, the page gets reloaded and you get the new value from the $_POST on witch you can readjust the data on your page (and reput the combobox on the selected item)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users