Jump to content

Submit not working ...


Jay2391

Recommended Posts

;D

 

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

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

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.