PHP - Submitting a form

Associate
Joined
24 Sep 2005
Posts
209
Would anyone be able to help me with the problem I'm having with the following code please?

I have a table of data, including FaultID, ComputerID etc, listing all faults in the database currently with the status "Attention". The purpose of this form is to assign a Priority to each of these listed faults, which will obviously update the database record.

I think this is the offending code:

Code:
if (isset($_POST['FaultPriority'])){
  // The author's details have been updated.

  $id = $_POST['id'];
  $ComputerID = $_POST['ComputerID'];
  $FaultPriority = $_POST['FaultPriority'];
  $sql = "UPDATE Fault SET
		  FaultPriority=$FaultPriority
          WHERE ComputerID='$ComputerID'";
  if (@mysql_query($sql)) {
    echo '<p>Workstation details updated.</p>';
  } else {
    echo '<p>Error updating workstation details: ' .
        mysql_error() . '</p>';
  }
}

There is no response from the php code when I click "SUBMIT" - it simply refreshes the page.

The entire code is as follows:

Thanks everyone.

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Helpdesk : All workstations requiring attention</title>
<meta http-equiv="content-type"
    content="text/html; charset=iso-8859-1" />
</head>
<body>
<h1>Manage Workstations</h1>
<?php

$dbcnx = @mysql_connect('localhost', 'root', '');
if (!$dbcnx) {
  exit('<p>Unable to connect to the ' .
      'database server at this time.</p>');
}

if (!@mysql_select_db('Technician_Support')) {
  exit('<p>Unable to locate the helpdesk ' .
      'database at this time.</p>');
}

 
    
if (isset($_POST['FaultPriority'])){
  // The author's details have been updated.

  $id = $_POST['id'];
  $ComputerID = $_POST['ComputerID'];
  $FaultPriority = $_POST['FaultPriority'];
  $sql = "UPDATE Fault SET
		  FaultPriority=$FaultPriority
          WHERE ComputerID='$ComputerID'";
  if (@mysql_query($sql)) {
    echo '<p>Workstation details updated.</p>';
  } else {
    echo '<p>Error updating workstation details: ' .
        mysql_error() . '</p>';
  }
}

// The basic SELECT statement
$select = 'SELECT FaultID, ComputerID, FaultStatus, FaultType, FaultDescription, StaffID, TechID, FaultPriority';
$from   = ' FROM Fault';
$where  = ' WHERE FaultStatus="Attention"';
$orderby = ' ORDER BY FaultID';

$sid = '100';


$roomid = '101';

?>
<?php

echo "<table cellpadding=0, cellspacing=0 border=1 align=center><tr>\n";
echo '<td width="90" align=center> Fault ID </td> <td width="90" align=center> Computer ID </td> <td width="90" align=center> Fault Type </td> <td width="200" align=center> Fault Description </td> <td width="90" align=center> Staff ID </td> <td width="90" align=center> Technician ID </td> <td width="90" align=center> Fault Priority </td>';
echo '</tr>'.'</table>';
$workstations = @mysql_query($select . $from . $where . $orderby);
if ($workstations) {
echo "<table cellpadding=0, cellspacing=0 align=center border=1><tr valign='top'>\n";
$statuses = array("Working","Attention","Faulty");
$counter = 0;
$faulty = 0;
$attention = 0;
$working = 0;

$str = "";





while ($computer = mysql_fetch_assoc($workstations)) {
	if (($counter) >= 1) {
		$str .= '</tr><tr valign="top">';
	}
	$counter++;
	$status = htmlentities($computer['FaultStatus']);

	$FaultID = $computer['FaultID'];
	$ComputerID = $computer['ComputerID'];
	$FaultType = $computer['FaultType'];
	$FaultDescription = $computer['FaultDescription'];
	$StaffID = $computer['StaffID'];
	$TechID = $computer['TechID'];
	$FaultPriority = $computer['FaultPriority'];

	if(in_array($status,$statuses)){
		$str .= '<td width="90">'.$FaultID.'</td>'.'<td width="90">'.$ComputerID.'</td>'.'<td width="90">'.$FaultType.'</td>'.'<td width="200">'.$FaultDescription.'</td>'.'<td width="90">'.$StaffID.'</td>'.'<td width="90">'.$TechID.'</td>'.'<td width="90">'.'<select size="1" name="FaultPriority"> 
<option value="Not Set" selected> Not Set </option>
<option value="High"> High </option>
<option value="Medium"> Medium </option> 
<option value="Low"> Low </option>/td>';

	} else {
		$str .= '<td align="center">-</td>';
	}

}


$str .= '</tr></table>';
echo $str;

}

?>

<form method="post" action="">
<input type="Submit" name="submit" value="Submit">
</form>
<p><a href="stations.php">New search</a></p>


</body>
</html>
 
Code:
  $id = $_POST['id'];
  $ComputerID = $_POST['ComputerID'];
  $FaultPriority = $_POST['FaultPriority'];

Echo these to make sure that they are being passed, and

FaultPriority=$FaultPriority should be FaultPriority = '$FaultPriority' just to be pedantic :)
 
There is no response from the php code when I click "SUBMIT" - it simply refreshes the page.

Code:
<form method="post" action="">

The action attribute has to specify the php page that deals with the information passed through the form. That is why the page is currently just refreshing!

I'm sure you know that though :) <-- haha
 
Last edited:
Aw come on everyone.

Code:
<form method="post" action="">
<input type="Submit" name="submit" value="Submit">
</form>
You gotta start the form before the inputs. ie here you have the form parts before the start of the form tag - see those <option /> thingies:

Code:
$str .= '<td width="90">'.$FaultID.'</td>'.'<td width="90">'.$ComputerID.'</td>'.'<td width="90">'.$FaultType.'</td>'.'<td width="200">'.$FaultDescription.'</td>'.'<td width="90">'.$StaffID.'</td>'.'<td width="90">'.$TechID.'</td>'.'<td width="90">'.'<select size="1" name="FaultPriority"> 
<option value="Not Set" selected> Not Set </option>
<option value="High"> High </option>
<option value="Medium"> Medium </option> 
<option value="Low"> Low </option>/td>';

	} else {
		$str .= '<td align="center">-</td>';
	}

}


$str .= '</tr></table>';
echo $str;

}

?>

<form method="post" action="">

If you look at the HTML outputted by your PHP it'd be much easier to troubleshoot :)
 
BOADC said:
The action attribute has to specify the php page that deals with the information passed through the form. That is why the page is currently just refreshing!

I'm sure you know that though :)

If you leave the action blank it submits the form back to the same page.

The problem is all your options actually sit outside the form so none of them are being passed back to the page.

Move the

Code:
<form method="post" action="">

Above the first table.
 
Beansprout said:
You wait all day and then two come along at once ;)

Are you calling me a bus! It's my glands... I would have been quicker, I was trying to chop up the code into something workiable but gave up half way through... :$
 
paulsheff said:
Are you calling me a bus! It's my glands... I would have been quicker, I was trying to chop up the code into something workiable but gave up half way through... :$
I guess if I'm calling you a bus I'm also calling me a bus :(
 
paulsheff said:
If you leave the action blank it submits the form back to the same page.

The problem is all your options actually sit outside the form so none of them are being passed back to the page.

Ah yeah, I still thought you'd have to specify the same page for it to work. I just saw the blank attribute and thought that was the problem. I'm still learning all this myself, so that'll teach me to think I'm smart and try to answer a question without looking properly :)
 
Back
Top Bottom