Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2012
    Posts
    1

    Red face Unanswered: Not able to store data from drop down list to db

    Not able to store data from drop down list to db

    I do no what wrong with my code, im not able to store data frm drop down list to database..its storing an empty data.

    registerform.php
    -------------------

    <html>
    <head>
    <?php
    $servername="localhost";
    $username="root";

    $conn= mysql_connect($servername,$username)or die(mysql_error());
    mysql_select_db("gsc track",$conn);
    $query = "SELECT managername FROM managers";
    $result = mysql_query($query);
    ?>



    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>register</title>
    </head>
    <body bgcolor="black" style="color:white;">


    <form name="forml" method="post" action="register.php" enctype="multipart/form-data">


    <h1>welcome to the registration page</h1>
    please input the registration details to create an account here<br>

    <table border="2">
    <tr>
    <td>User Name :</td><td><input name="regname" type="text" size"20"></input></td>
    </tr>
    <tr>
    <td>email :</td><td><input name="regemail" type="text" size"20"></input></td>
    </tr>
    <tr>
    <td>Team :</td><td><input name="regteam" type="text" size"30"></input></td>
    </tr>
    <tr>
    <td>password :</td><td><input name="regpass1" type="password" size"20"></input></td>
    </tr>
    <tr>
    <td>retype password :</td><td><input name="regpass2" type="password" size"20"></input></td>
    </tr>
    <tr>
    </tr>
    <td>Manager :</td>
    <td>
    <select name=mylist>

    <?php
    while ($nt= mysql_fetch_array($result))
    {

    Echo '<option value="' . $nt['manager_Id'] . '">' . $nt['managername'] . '</option>';

    }
    ?>
    </select>
    </td>

    </tr>
    </table>

    <input type="submit" name="submit" value="register me!"></input>

    </FORM>
    </body>
    </html>

    register.php
    ------------



    <?php


    if($_POST["regname"] && $_POST["regemail"] && $_POST["regteam"] && $_POST["regpass1"] && $_POST["regpass2"])
    {
    if($_POST["regpass1"]==$_POST["regpass2"])
    {
    $servername="localhost";
    $username="root";
    $conn= mysql_connect($servername,$username)or die(mysql_error());
    mysql_select_db("gsc track",$conn);

    mysql_query("INSERT INTO persons (username,email,team,password)values('$_POST[regname]','$_POST[regemail]','$_POST[regteam]','$_POST[regpass1]')");
    $keyid= mysql_insert_id();
    $mylist = $_POST['mylist'];

    mysql_query("INSERT INTO managers (user_Id,managername)values('{$keyid}','$mylist')" );

    print "<h1>you have registered sucessfully</h1>";

    print "<a href='index.php'>go to login page</a>";
    }
    else print "passwords doesnt match";
    }
    else print"invaild data";
    mysql_close($conn);
    ?>

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    suggest you use the or die construct or at least examine the muysql error number
    exmine the value of your SQL.

    in this case I'm pretty certtain its the SQL that is banjaxed
    PHP Code:
    $strSQL "INSERT INTO persons (username,email,team,password)
    values('"
    .$_POST[regname]."','".$_POST[regemail]."','".$_POST[regteam]."','".$_POST[regpass1]."');"
    numeric values must not be encapsulated by '
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

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