Jay2391 Posted February 4, 2007 Share Posted February 4, 2007 I have the code below but when I open the page it automaticly changes the update entry to the default I what to know why is not waitting for me to hiy the submit button to update... echo "<pre><h5>"; echo "Manual Status Change..."; print "<form action =\"tourney_admin.php?tourney_id=$tourney_id&chg_status=on\" method='post'>"; print '<select name="status_res"> <option value=""> -- Status Change Options -- </option>'; $qr_status = "SELECT * FROM $status_t"; $res_status = mysql_query($qr_status, $tc); while($row_status = mysql_fetch_array($res_status)){ $status_id = $row_status['status_id']; $status_res = $row_status['status']; print "<option value=\"$status_id\">$status_id - $status_res<br></option>"; if($status == $status_id){ $current_status = "$status_id - $status_res"; } } print "</select>"; $status_res = $_POST['status_res']; echo "<font color='white'> ***</font> "; print ' <input type="submit" name="submit" size"20" value="Change Status "/>'; echo "<br>You are Changing the status from :<font color='red'> $current_status</font><br>"; $status_update = $_POST['status_res']; $qr_status = "SELECT * FROM $status_t"; $res_status = mysql_query($qr_status, $tc); while($row_status = mysql_fetch_array($res_status)){ $status_id = $row_status['status_id']; $status_res = $row_status['status']; if($status_update == $status_id){ $new_status = "$status_id - $status_res"; } } $change_status = "UPDATE $tablet SET status='$status_update' WHERE (tourney_id=\"$tourney_id\")"; mysql_query($change_status) or die ("Cannot Update Table". mysql_error()); echo "REFRESH SCREEN TO VIEW CHANGES!!! --- NEW STATUS IS: <font color='red'> $new_status</font><br></h4>"; echo "</pre></h5>"; Link to comment https://forums.phpfreaks.com/topic/37063-submit-not-working/ Share on other sites More sharing options...
boo_lolly Posted February 4, 2007 Share Posted February 4, 2007 use if(isset($_POST['value'])) to only update after the submit button has been pressed. Link to comment https://forums.phpfreaks.com/topic/37063-submit-not-working/#findComment-177027 Share on other sites More sharing options...
Jay2391 Posted February 4, 2007 Author Share Posted February 4, 2007 where do I use it ... I try that but it didn't work Link to comment https://forums.phpfreaks.com/topic/37063-submit-not-working/#findComment-177028 Share on other sites More sharing options...
boo_lolly Posted February 4, 2007 Share Posted February 4, 2007 i'm taking a second look at your code. where is the variable $status coming from (in your first while loop)? what is its value? what does the if-statement do? also you need to post more code. Link to comment https://forums.phpfreaks.com/topic/37063-submit-not-working/#findComment-177035 Share on other sites More sharing options...
mainewoods Posted February 5, 2007 Share Posted February 5, 2007 your update code executes every time the page loads: $status_update = $_POST['status_res']; $qr_status = "SELECT * FROM $status_t"; $res_status = mysql_query($qr_status, $tc); while($row_status = mysql_fetch_array($res_status)){ $status_id = $row_status['status_id']; $status_res = $row_status['status']; if($status_update == $status_id){ $new_status = "$status_id - $status_res"; } } $change_status = "UPDATE $tablet SET status='$status_update' WHERE (tourney_id=\"$tourney_id\")"; mysql_query($change_status) or die ("Cannot Update Table". mysql_error()); --you need to move your php update code to the beginning the page and use an if to detect if the form has been submitted: if ($_POST) { //update code here } that way the update code does not execute on the first page load Link to comment https://forums.phpfreaks.com/topic/37063-submit-not-working/#findComment-177139 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.