anton_1 Posted August 11, 2011 Share Posted August 11, 2011 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(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/244546-updating-database-with-dropdown-value/ Share on other sites More sharing options...
manix Posted August 11, 2011 Share Posted August 11, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/244546-updating-database-with-dropdown-value/#findComment-1256118 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.