php
2015-04-15 84 views 0 likes 
0

我試圖讓這個工作幾個小時了,我認爲它與我有一個$ _GET ['ID']的事實有關;第一個腳本,但林不知道:SQL不更新行

腳本1(FORM):

<?php 
 
\t require_once('db_access.php'); 
 
\t $editID = $_GET['id']; 
 
    $query = mysql_query("SELECT * from routes where id = '".$editID."'"); 
 
    $row = mysql_fetch_assoc($query); 
 
?> 
 

 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
 
"http://www.w3.org/TR/html4/loose.dtd"> 
 
<html> 
 
<head> 
 
<title>Form Edit Data</title> 
 
</head> 
 
<body> 
 
<table border=1> 
 
    <tr> 
 
    <td align=center>Route Edit Data</td> 
 
    </tr> 
 
    <tr> 
 
    <td> 
 
     <table> 
 
     <form method="post" action="complete_edit.php"> 
 
     <tr>   
 
      <td>ID #</td> 
 
      <td> 
 
      <input type="hidden" name="formid" value="<?php echo $row['id'] ?>"> 
 
      </td> 
 
     </tr> 
 
     <tr> 
 
      <td>Route Name</td> 
 
      <td> 
 
      <input type="text" name="route_title" size="40" 
 
      value="<?php echo $row['route_title']?>"> 
 
      </td> 
 
     </tr> 
 
     <tr> 
 
      <td>Total Price</td> 
 
      <td> 
 
      <input type="text" name="total_price" size="40" 
 
      value="<?php echo $row['total_price']?>"> 
 
      </td> 
 
     </tr> 
 
     <tr> 
 
      <td>Down Payment</td> 
 
      <td> 
 
      <input type="text" name="down_payment" size="40" 
 
      value="<?php echo $row['down_payment']?>"> 
 
      </td> 
 
     </tr> 
 
     <tr> 
 
      <td>Weekly Net</td> 
 
      <td> 
 
      <input type="text" name="weekly_net" size="40" 
 
      value="<?php echo $row['weekly_net']?>"> 
 
      </td> 
 
     </tr> 
 
     <tr> 
 
      <td>Location</td> 
 
      <td> 
 
      <input type="text" name="location" size="40" 
 
      value="<?php echo $row['location']?>"> 
 
      </td> 
 
     </tr> 
 
     <tr> 
 
      <td>Remarks</td> 
 
      <td> 
 
      <input type="text" name="remarks" size="40" 
 
      value="<?php echo $row['remarks']?>"> 
 
      </td> 
 
     </tr> 
 
     <tr> 
 
      <td align="right"> 
 
      <input type="submit" 
 
      name="submit value" value="Edit"> 
 
      </td> 
 
     </tr> 
 
     </form> 
 
     </table> 
 
    </td> 
 
    </tr> 
 
</table> 
 
</body> 
 
</html>

SCRIPT 2(加工):

<?php 
 
\t \t $id = $_POSt['formid']; 
 
\t \t $editroute = $_POST['route_title']; 
 
\t  $editprice = $_POST['total_price']; 
 
\t  $editdownpay = $_POST['down_payment']; 
 
\t  $editweeklynet = $_POST['weekly_net']; 
 
\t  $editlocation = $_POST['location']; 
 
\t  $editremarks = $_POST['remarks']; 
 

 
\t  $query = "UPDATE routes SET id = '$id', route_title = '$editroute', total_price = '$editprice', down_payment = '$editdownpay', weekly_net = '$editweeklynet', location = '$editlocation', remarks = '$editremarks' WHERE id = '$id'"; 
 
\t  header('Location:index.php'); 
 
?> \t  \t

Th Ë第一大量的代碼是我的形式放置,第二個是在處理髮生 感謝您的幫助的人:) 亞歷

+0

'$ _POSt ['formid'];'應該''_ _POST [' formid'];'也不要相信用戶輸入,但這似乎不會去DB,所以也許你只是測試? – chris85

+0

我已驗證所有POST數據正在處理complete_edit.php但沒有更新? –

回答

1
$id = $_POSt['formid']; 

$ _ POST不是$ _ POST

0

林後真是太傻了閱讀評論到這裏的問題,我意識到我沒有mysql_query字符串:) 感謝球員給我我的心靈哈哈:) 亞歷克斯

+0

不要忘記不信任用戶輸入。 https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php?rq=1 – chris85

+0

我沒有開始消毒領域,如果這就是你的意思:) –

+0

是的,這就是我意思。至少爲了ids把它們作爲整數。 '$ editID =(int)$ _ GET ['id'];'(如果它們是整數) – chris85

相關問題