Page 1 of 1

form in my script does not send hidden input value [SOLVED]

Posted: Fri Sep 14, 2007 10:38 pm
by lafflin
Hello, I have a script here in it's infancy, I can't seem to figure out why my hidden input "submitted" does not send it's value when sent via POST to the same script. I have an IF ($_POST['submitted']) {do this } else{ do that} and it just keeps "doing that".

This should be something easy as the code is pretty simple, but whatever it is I'm just not seeing it, I've been looking for a while, but I'm not comming up with anything.

Any help is greatly appreciated,

Thanks.

Code: Select all

<?php
# EDIT STUDENTS
// This script ALLOWS YOU TO VIEW ALL OF A PARTICULAR STUDENTS INFORMATION

$page_title = 'EDIT STUDENT';
session_start();



if(isset($_GET['sid']))          {   $sid = $_GET['sid']  ;    }

if(isset($_POST['submitted']))   {
echo 'subd' ; 
$sid = $_POST['sid'] ;

            $update_query = " UPDATE 
                                      student_info 
			                   SET	 
			
	                                   first_name = '".$_POST['fn']."''
		                       WHERE
			                           sid = $sid";
	$updated = mysql_query ($update_query) or die($update_query); // Run the query.


    if ($updated) {


 //======================SEND EM BACK TO VIEW-EDIT=========================


			// Redirect the user to the next page.
				// Start defining the URL.
				$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
				
				// Check for a trailing slash.
				if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) {
					$url = substr ($url, 0, -1); // Chop off the slash.
				}
				
				// Add the page.
				$url .= '/view_edit.php?sid=' .$_POST['sid']. '';
				
				header("Location: $url");
				exit();  
				         }  else { echo 'you still suck'; 
						 
						 
						  // If it did not run OK.
		include ('./includes/header.inc.htm');
			echo '<h1 id="mainhead">System Error</h1>
			<p class="error">You could not be registered due to a system error. We apologize for any inconvenience.</p>'; // Public message.
			echo '<p>' . mysql_error() . '<br /><br />Query: ' . $query . '</p>'; // Debugging message.
			
			exit();
		                                      
		
		mysql_close(); // Close the database connection.
		}  //--------------------END IF QUERY DID NOT RUN OK---------------------
						}  else  {  echo 'subd not posted';}//----------------------END OF IF UPDATED-------------------

require_once ('./includes/mysql_connect.php'); // Connect to the db.
		
// Make the query.
$query = "SELECT sid, first_name, last_name, sex, school, date_format(dob,'%c/%e/%y'),  active, medical_issues, secret_classification,  name 		
FROM student_info   
LEFT JOIN classes_students 
USING ( sid ) 
LEFT JOIN classes 
USING ( cid )  
WHERE
sid = '$sid'";
$result = mysql_query ($query) or die($query); // Run the query.

if ($result) {

include ('./includes/header.inc.htm');    //++++++++++++++++++++++++START BROWSER COMMO+++++++++++++++++++++++++++++++++++
// Page header.
echo '<h1 id="mainhead" align="center">EDIT STUDENT RECORD</H1>  
      <form id="form" name="form" method="POST" action="edit.php">'   ;
// Table header.
	echo '<table align = "center"><td><table align="center" cellspacing="0" cellpadding="5">
	<tr  height ="4px" bgcolor ="#bbbbbb"><td colspan="11"></td></tr>';
	
	// Fetch and print all the records.
$row = mysql_fetch_array($result, MYSQL_ASSOC) ;
  echo '
          <tr height="2px" bgcolor="#000000"><td colspan ="12"></td></tr>
		  
          <tr bgcolor="#770000">
	           <td align ="center">'.$row['sid'].'</td>
		       <td><font color ="#000000">::</font></td>
			   
			   <td align="center"><font color="#888888">Name:</font><input type ="text" name ="fn" value =" '.$row['first_name'] .'"/>               </td>
			   <td><font color ="#000000">::</font></td>
			   
		  </tr>
		  <tr> 
		    <td>
		       <div align ="center">
			       <input type="hidden" value="submitted"/>
	               <input type="submit" name ="submit" value="submit"/>
			   </div>
			 </td>  
		  </tr>
		        
	    </table>
		</form>
     </body>
  </html>' ;
  
    } else
	       {  echo 'You have reached this message in error'    ;
		   											        }
		   


?>

Posted: Fri Sep 14, 2007 10:43 pm
by s.dot
You have to give the field a name.

Posted: Fri Sep 14, 2007 11:17 pm
by lafflin
aww man! you'd think that I might have picked up on that after looking at it for an hour.
Thanks alot.

you have to...

Posted: Fri Sep 14, 2007 11:53 pm
by navindhar
you have to mention 'id' or 'name' for your hidden field.

hidden form input not working solved

Posted: Sat Sep 15, 2007 8:44 am
by lafflin
Closed discussion, issue solved.