2013-02-21 49 views
0

我一直在测试我的SQL在phpmyadmin,我知道SQL工作正常,但当我通过表单按钮调用它时,它什么都不做。任何人都可以告诉我我做错了什么。使用PHP更新MySQL记录 - SQL的作品,PHP方面不

这是在主窗体页面中的PHP:

<?php 
    echo 
    "<table border='1'> 
    <tr> 
<th>Firstname</th> 
<th>Lastname</th> 
<th>Age</th> 
<th>Hometown</th> 
<th>Job</th> 
<th>health</th> 
<th>damage</th> 
</tr>"; 

while($row = mysql_fetch_row($result)) { 

    echo '<tr>'; 
    foreach($row as $cell) { 

     echo "\n<td>$cell</td>"; 
    } 

    echo '<td><form method="POST" action="attack.php"> 
    <input name="update" type="button" value="Update Record" /> 
    <input type="hidden" name="'.$row[1].'" /></form></td></tr>'; 
    echo "\n\n"; 
    echo "test"; 

} 
?> 

<?php 
require_once('config.php'); 

$sqltest = $sqltest - 5; 
    $id = floor($_GET['id']); 

if($id > 0) 
{ 
$sql1="UPDATE ajax_demo SET Health = Health - Damage"; 
$result=mysql_query($sql1); 
mysql_close(); 
} 
?> 

obvisouly我想补充的可变因素NITO SQL字符串但是出于测试目的,我离开了它本身。如果任何人都可以提供帮助,那么它将会受到很大的困扰。

+1

$ SQL1 = “UPDATE ajax_demo SET健康=健康 - 伤害'”; 改变这一点。 – Dgo 2013-02-21 11:15:07

+0

1)当你用HTML注入时,你不会转义数值。 2)你不检查'mysql_query()'是否成功。 3)您正在使用已弃用的扩展名。 – 2013-02-21 11:18:55

+0

ÁlvaroG. Vicario可以延长这些点吗? – user1284386 2013-02-21 11:31:16

回答

0

使用此查询

$sql1="UPDATE ajax_demo SET `Health` = `Health` - `Damage`"; // it will set the actual computed value. 

如果使用

`Health` = 'Health - Damage' // it will set text Health - Damage not the computed value 
+0

啊非常感谢,这已经改变。还有什么其他原因会导致现在不行? – user1284386 2013-02-21 11:31:43

+0

@ user1284386尝试我的代码,它工作正常。我测试过了。 – 2013-02-21 11:32:45

+0

感谢您的快速回复,您是否通过像我这样的表单调用它?所以在BTN点击action = attack.php? – user1284386 2013-02-21 11:38:09