dongying3744 2014-12-15 04:50
浏览 37

从下拉菜单中选择选项后无法更新记录

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 :)

  • 写回答

1条回答 默认 最新

  • dongxianghuan3587 2014-12-15 04:58
    关注

    Try this:

    $query="UPDATE complaints SET status='close' WHERE complaintid=$cmpi";
    

    removed ` surrounding $cmpi.

    评论

报告相同问题?

悬赏问题

  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思