2015-04-06 107 views
-1

我正在用PHP編寫代碼來更新表格。發佈錯誤的值

<form action="" method="POST"> 
<td><div align="center"><input type="text" name="id" value="<?php echo $Result['id']; ?>" readonly /></div></td> 
<td><div align="center"><input type="text" name="studentid" value="<?php echo $Result['studentid']; ?>" /></div></td> 
<td><div align="center"><input type="text" name="subjectid" value="<?php echo $Result['subjectid']; ?>" /></div></td> 
<td><div align="center"><input type="text" name="marks" value="<?php echo $Result['marks']; ?>" /></div></td> 
<td><div align="center"><input type="text" name="term" value="<?php echo $Result['term']; ?>" /></div></td> 
<td><div align="center"><input type="text" name="year" value="<?php echo $Result['year']; ?>" /></div></td> 
<td><div align="center"><input type="text" name="rank" value="<?php echo $Result['rank']; ?>" /></div></td> 
<td><input type="submit" name="save" value="Save" /></td> 
<td><input type="submit" value="Cancel" OnClick="window.location='<?=$_SERVER["PHP_SELF"];?>';" /></td> 
<td></td> 
</form> 

我遇到的錯誤是,它張貼收到的價值,而不是改變一個(在頁面上編輯修改)

+0

給你完整的代碼。 – 2015-04-06 06:02:48

+0

onclick處理程序是多餘的,只是讓它提交 – Ghost 2015-04-06 06:03:04

+0

也顯示您的php代碼。或者嘗試在提交中更改按鈕,並在表單操作中寫入php_self。 – 2015-04-06 06:03:11

回答

1

這是從那裏你可以更新你的數據的編輯頁面。我已經使用我的數據庫連接首先你必須改變數據庫和表名。

而且您應該以查詢字符串形式(如edit.php?id=12)的形式通過該行的id

<?php 
     mysql_connect("localhost","root","root"); 
     mysql_select_db("test"); 
     $id=$_GET['id']; 
    if(isset($_POST['save'])) 
    { 

     $id=$_POST['id']; 
     $st_id=$_POST['studentid']; 
     $sub_id=$_POST['subjectid']; 
     $marks=$_POST['marks']; 
     $term=$_POST['term']; 
     $year=$_POST['year']; 
     $rank=$_POST['rank']; 
      $sql="UPDATE `test`.`user` SET `st_id` = '$st_id', 
       `sub_id` = '$sub_id', 
       `mark` = '$marks', 
       `term` = '$term', 
       `year` = '$year', 
       `rank` = '$rank' WHERE `user`.`id` =`$id`"; 
     mysql_query($sql); 
    } 
    $result=mysql_query("select * from user where id=$id"); 
    $Result=mysql_fetch_array($result); 
    ?> 
    <!DOCTYPE html> 
    <html> 
    <head> 
     <title> 

     </title> 
    </head> 
    <body> 
    </html> 
    <form action="" method="POST"> 
    <td><div align="center"><input type="text" name="id" value="<?php echo $Result['id']; ?>" readonly /></div></td> 
    <td><div align="center"><input type="text" name="studentid" value="<?php echo $Result['st_id']; ?>" /></div></td> 
    <td><div align="center"><input type="text" name="subjectid" value="<?php echo $Result['sub_id']; ?>" /></div></td> 
    <td><div align="center"><input type="text" name="marks" value="<?php echo $Result['mark']; ?>" /></div></td> 
    <td><div align="center"><input type="text" name="term" value="<?php echo $Result['term']; ?>" /></div></td> 
    <td><div align="center"><input type="text" name="year" value="<?php echo $Result['year']; ?>" /></div></td> 
    <td><div align="center"><input type="text" name="rank" value="<?php echo $Result['rank']; ?>" /></div></td> 
    <td><input type="submit" name="save" value="Save" /></td> 
    <td><input type="submit" value="Cancel" OnClick="window.location='<?=$_SERVER["PHP_SELF"];?>';" /></td> 
    <td></td> 
    </form> 
    </body> 
    </html> 
+0

它不起作用。 – Bhaamb 2015-04-06 06:41:56

+0

錯誤保存[在'where子句'中未知的列'12'] – Bhaamb 2015-04-06 06:44:31

+0

我檢查了@Bhaamp它正在工作只要你點擊編輯按鈕像 2015-04-06 06:46:32