如何在mysql中更新表单选择2行值

时间:2013-11-25 09:18:35

标签: php mysql sql

如何使用php

更新mysql中的表单选择2行值

我有这个链接

floorsedit.php?id=Building1&floorno=1

当我访问此链接时 它显示空白请告诉我为什么它显示空白以及为什么它不更新 我认为有一个问题就是为什么它没有显示任何内容

$sql="SELECT * FROM $tbl_name where buildingname='".$id."' and floorno='".$floorno."' ";

请帮我解决这个问题

感谢 ...

这是主页

floorsedit.php      

    $host="localhost"; // Host name 
    $username="root"; // Mysql username 
    $password=""; // Mysql password 
    $db_name="building"; // Database name 
    $tbl_name="floors"; // Table name

    // Connect to server and select database.
    mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
    mysql_select_db("$db_name")or die("cannot select DB");

    // get value of id that sent from address bar
     $id = $_GET['id']; 

     $floorno = $_GET['$floorno'];

    // Retrieve data from database 
    $sql="SELECT * FROM $tbl_name where buildingname='".$id."' and floorno='".$floorno."' ";
    $result=mysql_query($sql);
    $rows=mysql_fetch_array($result);
    ?>
    <?php
    // close connection 
    mysql_close();
    ?>

and this is a form
<form name="form1" method="post" action="update_ac.php" class="registration_form">

  <fieldset>
    <legend>New Floor </legend>
<input name="id" type="hidden" id="buildingname" value="<? echo $rows['buildingname']; ?>">

    <p>Create A New Floor of Building <span class="style4" style="background:#EAEAEA none repeat scroll 0 0;line-height:1;margin-left:410px;;padding:9px 9px;">Please Fill the All Info </span> </p>

    <div class="elements">
      <label for="buildingname">Building Name  :</label>
      <input type="text" id="buildingname" name="buildingname" value="<? echo $rows['buildingname']; ?>" size="25" />
       <label2 for="floorno">Floor No   :</label2>
      <input type="text" id="floorno" name="floorno" value="<? echo $rows['floorno']; ?>" size="25" />
</div>
    <div class="elements">
      <label for="flatno">Floor No of Flats  :</label>
      <input type="text" id="flatno" name="flatno" value="<? echo $rows['flatno']; ?>" size="25" />

    </div>

    </p >

    <div class="submit">
<input type="submit" name="Submit" value="Submit">
    </div>
  </fieldset>
</form>

update_ac.php

<?php
$host="localhost"; // Host name 
$username="root"; // Mysql username 
$password=""; // Mysql password 
$db_name="building"; // Database name 
$tbl_name="floors"; // Table name 

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

// update data in mysql database 
$sql="UPDATE $tbl_name SET buildingname='$buildingname', floorno='$floorno', flatno='$flatno' WHERE buildingname='$id' AND floorno='$floorno'";
$result=mysql_query($sql);

// if successfully updated. 
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='vieweditfloor.php'>View result</a>";
}

else {
echo "ERROR";
}

?>

1 个答案:

答案 0 :(得分:1)

在floorsedit.php中,使用

$floorno = $_GET['floorno'];

而不是

$floorno = $_GET['$floorno'];

我认为问题出在这一行。希望它有所帮助...