anton_1 Posted August 12, 2011 Share Posted August 12, 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', 'mypassword'); 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/244592-update-database-with-dropdown-list-value/ Share on other sites More sharing options...
WebStyles Posted August 12, 2011 Share Posted August 12, 2011 in this part: $ID = $row['id']; $year = $row['AssignedTo']; echo "<option value=$id>$year"; try: $id = $row['id']; $year = $row['AssignedTo']; echo "<option value='".$id."'>".$year."</option>"; $ID and $id are two different things (one uppercase, one lowercase). Do they both exist? do they have the correct values? what does your error_reporting say? (check your error logs) You're also not closing your <option> elements. Quote Link to comment https://forums.phpfreaks.com/topic/244592-update-database-with-dropdown-list-value/#findComment-1256334 Share on other sites More sharing options...
anton_1 Posted August 12, 2011 Author Share Posted August 12, 2011 thank you ever so much! How would I recieve that value in the update page? Quote Link to comment https://forums.phpfreaks.com/topic/244592-update-database-with-dropdown-list-value/#findComment-1256375 Share on other sites More sharing options...
WebStyles Posted August 12, 2011 Share Posted August 12, 2011 $value = $_POST['Assign']; Quote Link to comment https://forums.phpfreaks.com/topic/244592-update-database-with-dropdown-list-value/#findComment-1256376 Share on other sites More sharing options...
anton_1 Posted August 12, 2011 Author Share Posted August 12, 2011 The only thing that displays is the record updated although nothing is being updated. $value = $_POST['Assign']; isnt showing anything Thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/244592-update-database-with-dropdown-list-value/#findComment-1256380 Share on other sites More sharing options...
WebStyles Posted August 12, 2011 Share Posted August 12, 2011 you need to do that for each select name you have. Quote Link to comment https://forums.phpfreaks.com/topic/244592-update-database-with-dropdown-list-value/#findComment-1256386 Share on other sites More sharing options...
anton_1 Posted August 12, 2011 Author Share Posted August 12, 2011 This help is really appreciated WebStyles! this is what I have now 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."</option>"; } echo "</select>"; echo "</p>"; to this page: <?php $value = $_POST['Assign']; mysql_connect('localhost', 'web101-db1-1', 'Hiyapal2'); mysql_select_db('web101-db1-1'); $query="UPDATE Helpdesk WHERE AssignedTo ='$ud_id'"; mysql_query($query); echo "Record Updated"; mysql_close(); ?> Nothing being displayed? Quote Link to comment https://forums.phpfreaks.com/topic/244592-update-database-with-dropdown-list-value/#findComment-1256387 Share on other sites More sharing options...
WebStyles Posted August 12, 2011 Share Posted August 12, 2011 try: echo $value = $_POST['Assign']; instead of just $value = $_POST['Assign']; (so you can see if the variable is reaching the page) Quote Link to comment https://forums.phpfreaks.com/topic/244592-update-database-with-dropdown-list-value/#findComment-1256402 Share on other sites More sharing options...
anton_1 Posted August 12, 2011 Author Share Posted August 12, 2011 <?php echo $value = $_POST['Assign']; mysql_connect('localhost', 'web101-db1-1', 'Hiyapal2'); mysql_select_db('web101-db1-1'); $query="UPDATE Helpdesk WHERE AssignedTo ='$ud_id'"; mysql_query($query); echo "Record Updated"; mysql_close(); ?> Still displaying nothing, it doesnt seem to be taking the value from the previous page Quote Link to comment https://forums.phpfreaks.com/topic/244592-update-database-with-dropdown-list-value/#findComment-1256404 Share on other sites More sharing options...
TeNDoLLA Posted August 12, 2011 Share Posted August 12, 2011 A little offtopic, but I would suggest using var_dump($var); instead of echo because this shows you more debug information. If the variable does not reach the page, and you try to use the variable on that page you should get some WARNING something like call to undefined variable or similar. Do you have error reporting also turned on? this in the beginning of your scripts ini_set('display_errors', 1); error_reporting(-1); Quote Link to comment https://forums.phpfreaks.com/topic/244592-update-database-with-dropdown-list-value/#findComment-1256407 Share on other sites More sharing options...
anton_1 Posted August 12, 2011 Author Share Posted August 12, 2011 string(0) "" Notice: Undefined variable: ud_id in /home/sites/mysite/public_html/UpdateFields.php on line 19 Record Updated thats what im getting now Quote Link to comment https://forums.phpfreaks.com/topic/244592-update-database-with-dropdown-list-value/#findComment-1256411 Share on other sites More sharing options...
TeNDoLLA Posted August 12, 2011 Share Posted August 12, 2011 So from this we can see that the variable does reach the page, but it contains value of empty string. Then you get the notice for using variable $ud_id in the SQL query, but you have not set this variable before using it. Where does this $ud_id come from? Quote Link to comment https://forums.phpfreaks.com/topic/244592-update-database-with-dropdown-list-value/#findComment-1256433 Share on other sites More sharing options...
anton_1 Posted August 12, 2011 Author Share Posted August 12, 2011 That was an old variable which I have now changed. <?php ini_set('display_errors', 1); error_reporting(-1); $value = $_POST['Assign']; var_dump($value); mysql_connect('localhost', 'web101-db1-1', ''); mysql_select_db('web101-db1-1'); $query="UPDATE Helpdesk WHERE AssignedTo ='$value'"; mysql_query($query); echo "Record Updated"; mysql_close(); ?> Thanks Quote Link to comment https://forums.phpfreaks.com/topic/244592-update-database-with-dropdown-list-value/#findComment-1256435 Share on other sites More sharing options...
TeNDoLLA Posted August 12, 2011 Share Posted August 12, 2011 Please use code tags in the future. Quote Link to comment https://forums.phpfreaks.com/topic/244592-update-database-with-dropdown-list-value/#findComment-1256455 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.