+ Reply to Thread
Results 1 to 3 of 3

Thread: Drop Down Menu -> Mysql

  1. #1
    White-Fox is offline x10Hosting Member White-Fox is an unknown quantity at this point
    Join Date
    Aug 2008
    Posts
    3

    Drop Down Menu -> Mysql

    Hey, I'm trying to add data from a drop down menu into my database... But What I did does not work.

    PHP Code:
    <?php
    if(isset($_POST['save']))
    {
       
    $itemn   $_POST['itemn'];
       
    $realm $_POST["realm"];

       if(!
    get_magic_quotes_gpc())
       {
          
    $itemn   addslashes($itemn);
       }

       
    $query " INSERT INTO items (itemn, realm) ".
                
    " VALUES ('$itemn, '$realm')";
       
    mysql_query($query) or die('Error ,query failed');

       echo 
    "'$itemn' on '$realm' added";
    }
    ?>
    <form method="post">
    <table width="700" border="0" cellpadding="2" cellspacing="1" align="center">
    <tr>
    <td width="100">Item Name</td>
    <td><input name="itemn" type="text"></td>
    </tr>
    <tr>
    <td width="100">Realm</td>
    <td>


    <select name="realm">
        <option value="------" >Select one</option>
        <option value="Us.East N-L Sofcore">Us.East N-L Sofcore</option>
        <option value="Us.East N-L Hardcore">Us.East N-L Hardcore</option>
        <option value="Us.East L Softcore">Us.East L Softcore</option>      
        <option value="Us.East L Hardcore">Us.East L Hardcore</option>
        <option value="Us.West N-L Sofcore">Us.West N-L Sofcore</option>
        <option value="Us.West N-L Hardcore">Us.West N-L Hardcore</option>
        <option value="Us.West L Softcore">Us.West L Softcore</option>        
        <option value="Us.West L Hardcore">Us.West L Hardcore</option>
        <option value="Europe N-L Sofcore">Europe N-L Sofcore</option>
        <option value="Europe N-L Hardcore">Europe N-L Hardcore</option>
        <option value="Europe L Softcore">Europe L Softcore</option>             
        <option value="Europe L Hardcore">Europe L Hardcore</option>           
        <option value="Asia N-L Sofcore">Asia N-L Sofcore</option>
        <option value="Asia N-L Hardcore">Asia N-L Hardcore</option>
        <option value="Asia L Softcore">Asia L Softcore</option>           
        <option value="Asia L Hardcore">Asia L Hardcore</option>
    </select>

    </td>
    </tr>
    </table>

    <input name="save" type="submit" value="Save Item">
    </form>

  2. #2
    leafypiggy's Avatar
    leafypiggy is offline Community Advocate leafypiggy is on a distinguished road
    Join Date
    Aug 2007
    Location
    Massachusetts
    Posts
    2,228

    Re: Drop Down Menu -> Mysql

    you don't specifiy an action to do once submit is pressed.

    you gotta change
    Code:
    <form method="post">
    to

    Code:
    <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">

    that will just make the form submit the values to taht file that you have the proccessing of the form.
    Neil Hanlon | x10Hosting Support Representative
    Neil[at]x10hosting.com
    █ I'm always happy to help. Just ask a question in Free Hosting
    Terms of Service IRC

  3. #3
    White-Fox is offline x10Hosting Member White-Fox is an unknown quantity at this point
    Join Date
    Aug 2008
    Posts
    3

    Re: Drop Down Menu -> Mysql

    Quote Originally Posted by leafypiggy View Post
    you don't specifiy an action to do once submit is pressed.

    you gotta change
    Code:
    <form method="post">
    to

    Code:
    <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    that will just make the form submit the values to taht file that you have the proccessing of the form.
    It is not that at all

    PHP Code:
    " VALUES ('$itemn, '$realm')"
    I forgot a ' after the itemn
    Last edited by White-Fox; 09-01-2008 at 02:21 PM.

+ Reply to Thread

Similar Threads

  1. [PHP] MySQL and PHP
    By Bryon in forum Tutorials
    Replies: 43
    Last Post: 03-24-2011, 07:27 AM
  2. New Site-Suggestions?
    By mnoutside in forum Review My Site
    Replies: 9
    Last Post: 08-27-2008, 07:01 AM
  3. help!! coding advanced drop down menu
    By zynischen in forum Programming Help
    Replies: 3
    Last Post: 04-25-2008, 05:14 PM
  4. coding advanced drop down menu
    By zynischen in forum Programming Help
    Replies: 0
    Last Post: 04-20-2008, 04:13 AM
  5. Have a problem with my forum
    By tikloos in forum Scripts & 3rd Party Apps
    Replies: 43
    Last Post: 01-19-2006, 01:14 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers