Jump to content

Updating database with dropdown value


anton_1

Recommended Posts

Hey guys, Every help would be greatly apperciated!

 

having a bit of bother updating my database when a user selects a value from the drop down menu

 

here is the code:

 

 

 

echo '<form action="UpdateFields.php" method="post">';

$data = @mysql_query("select AssignedTo from Tickets");

echo "<p>Assigned To:";

echo '<br>';

echo '<br>';

echo '<Select Name="Assign">';

while ($row = mysql_fetch_assoc($data))

{

$ID = $row['id'];

$year = $row['AssignedTo'];

echo "<option value=$id>$year";

}

echo "</select>";

echo "</p>";

 

$data = @mysql_query("select Status from Tickets");

echo "<p>Status:";

echo '<br>';

echo '<br>';

echo '<Select Name="Stat">';

while ($row = mysql_fetch_assoc($data))

{

$ID = $row['id'];

$year = $row['Status'];

echo "<option value=$id>$year";

}

echo "</select>";

echo "</p>";

 

echo '<br>';

echo '<br>';

 

echo  '<input type="submit" name="update" value="Update!" />';

 

echo '</form>';

 

 

goes to:

 

<?php

 

 

$ud_id = $_POST['Assign'];

 

 

 

 

mysql_connect('localhost', 'web101-db1-1', 'Hiyapal2');

mysql_select_db('web101-db1-1');

 

 

 

 

 

 

$query="UPDATE Helpdesk '";          //not sure what goes here

mysql_query($query);

echo "Record Updated";

mysql_close();

 

 

 

 

 

?>

 

 

 

 

 

 

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/244546-updating-database-with-dropdown-value/
Share on other sites

In order to execute the second file which you referred as "goes to" the submit button has to be clicked so the form sends the data,

 

If you wish to run an external script file (which would in your case mean update the database) you need to use AJAX in your select tag.

 

just a quick notice at first glance you never close your option tags, also you don't need to execute an echo at every single next line like so:

 

echo "<p>Assigned To:";

echo '<br>';

echo '<br>';

echo '<Select Name="Assign">';

 

You can just

 

echo "<p>Assigned To:<br><br><Select Name='Assign'>';

 

Or

 

echo "

  <p>Assigned To:

  <br>

  <br>

  <Select Name='Assign'>';

 

same thing

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.