php - Posting drop down menu value to mysql cell


Alrighty, so i'm quite a beginner when it comes to PHP and MySQL programming so the problem might be quite noobish but anyway here's my situation. I've got a content page with a dropdown menu that should give me a $_POST value (the options are taken from a database column): here's the code for that

    <link href="../css/pagestyle.css" rel="stylesheet" type="text/css" />

    $db = mysqli_connect($server, $username, $password, $database);
    if(mysqli_connect_errno()) { //if connection database fails
     echo("Connection not established " .
     mysqli_connect_error($db) . "</p>");

    $query = "SELECT username FROM users WHERE email = '1' ORDER BY username ASC";

    $result = mysqli_query($db,$query);

    if (!$result) { 
     echo("Error, the query could not be executed: " .
     mysqli_error($db) . "</p>");

    echo "
  <form action='myscript' method='post'>
   <select name='test'>
        <option value = 'none' selected = 'selected' >
          `Select a DJ:` </option>";

    while ($row = mysqli_fetch_assoc($result)){
     echo '<option value="' . $row['username'] . '">' . $row['username']. '</option>';
     <input type='submit' value='submit' name='submit'>
    </form> ";

Quite a bit of code for such a small function i know. Anyway the drop down menu gets its options from a database column and that works fine, now when i press the submit button, it runs another php page that's coded like this:

<link href="../css/pagestyle.css" rel="stylesheet" type="text/css" /><html>

$con = mysqli_connect($server, $username, $password, $database);
if (mysqli_connect_errno())
  echo "Failed to connect to MySQL: " . mysqli_connect_error();

$id = $_POST['test'];

$order = "UPDATE  `habboxli_system`.`users` SET  `points` = points+1 WHERE  `users`.`username` ='$id'";

echo "name is $id";

echo "Vote posted!";

This code should take the value that was chosen in the drop down menu and use it to update a specific cell in the database, i signed it to a variable called $id just for testing purposes but the value seems to be blank, so from that i presume that the drop down menu didn't return a value when it navigated from the original page ( to the myscript.php page ( Any help on how to get this to work would be much appreciated.




As was said in the comments, you are using the mysql_query function mixed in with the mysqli functions.

I got the code to work for me by changing



mysqli_query($con, $order);

You can also debug what was passed to the script by simply printing the $_POST array:


People are also looking for solutions to the problem: PHP Simple HTML DOM If Website is Down


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.