Jump to content

Update SQL-populated dropdown after submit


stirrah

Recommended Posts

Hello everyone!

 

I am populating a dropdown with results from a sql query. After that I am deleting something by pressing the submit button that relates to this dropdown. The submit works and it is deleting the row in my DB, however the new result doesnt show before i reload the page. How can I make my dropdown update itself when I press submit so I can see the updated sql results?

 

 

 

 

Link to comment
Share on other sites

sounds like your logic on the page is producing the dropdown before the logic that is deleting the rows in the database table.

 

code on a page should be organized with any action/processing first, then produce and output any content.

 

if that doesn't sound like what is causing the problem, you would need to post your code.

Link to comment
Share on other sites

Okey, I understand what you mean. But I'm not sure how to do it any other way. This is my code:

 

First I fetch users from DB:

$usersquery = mysql_query("SELECT * blablabla)");
while($row = mysql_fetch_array($usersquery)) {
    $users .="<option value=\"".$row['user_id']."\">" . $row['username'] . "</option>";
}

Then I show them in a dropdown / add submit button:

 <?php echo $users ?> </select>

<input type="submit" value="add_assigne" name="add_assigne"> 
      </li>
      <?php if (empty($_POST['add_assigne']) === false) {
add_assigne($user_1, $_POST['assigne'], $pid);

 

This is working, but I want the dropdown to update itself with the new users after submit is pressed...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.