Assignment background :
I have a drop down menu which I am populating from a database. Based on the option user choses from the drop down , I need to update the chosen record. Now some information on the databases and the record types : There are 5 types of complaints : Electrical, Mechanical , Telephone , Fire System and Priority. Each of these complaints can have a status of either "open" or "close". So when the user chooses "Electrical type" , all the "open" complaint-id's (complaint id is a field in the same record) of electrical types will appear. Once the admin chooses the id, the corresponding record is to be updated to change the status to "close".
Now my problem :
I am able to display all the complaint ids , but upon choosing the concerned id and hitting the submit button , the status of the record does not change to "close".
The code
$user="root";
$password="";
$database="complaint_data";
$localhost="localhost";
mysql_connect($localhost,$user,$password);
@mysql_select_db($database) or die("Unable to open database");
echo ('<form action="" method="post"><br>');
echo ('<center><select name = "complaint"></center>');
echo ('<option value ="Electrical"> Electrical </option>');
echo ('<option value ="Mechanical"> Mechanical </option>');
echo ('<option value ="Telephone"> Telephone </option>');
echo ('<option value ="Fire"> Fire </option>');
echo ('<option value ="Priority"> Priority </option>');
echo ('<center><input type="submit" name="Submit" ></center>');
echo ('</form>');
if(($_SERVER["REQUEST_METHOD"]=="POST") and (!empty($_POST['Submit']) ) ){
$t=$_POST['complaint'];
switch ($t) {
case "Electrical":
$q="SELECT `complaintid` , `comment` FROM `complaints` WHERE `status`='open' and `type`='Electrical' ORDER BY `id` DESC";
$sql=mysql_query($q);
$count=mysql_num_rows($sql);
if($count!=0) {
echo ('<form action="" method="post"><br>');
echo ('<center><select name = "complaint1"></center>');
while($row=mysql_fetch_array($sql)) {
$cmp=$row['complaintid'];
echo "<option value =\"$cmp\"> $cmp </option> <br>";
}
echo ('</select>');
echo ('<center><input type="submit" name="Submit1" ></center>');
echo ('</form>');
if(($_SERVER["REQUEST_METHOD"]=="POST") and (!empty($_POST['Submit1'])) ) {
$cmpi=$_POST['complaint1'];
echo $cmpi;
$query="UPDATE complaints SET status='close' WHERE complaintid=`$cmpi` ";
mysql_query($query);
}
}
if($count=='0') {
echo "No record of electrical type found";
}
mysql_close();
break;
By the way I have included only the snippet for Electrical type, once it works I shall copy it to other types too ! TIA :)