2013-02-21 2 views
0

입니다. phpmyadmin에서 제 SQL을 테스트 해봤는데 SQL은 잘 작동합니다. 그러나 폼 버튼을 통해 호출 할 때 아무 것도하지 않습니다. 누구나 내가 뭘 잘못하고 있는지 아이디어를 줄 수 있을까? PHP로 MySQL 레코드 업데이트하기 - SQL은 작동하지 않습니다. 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 내가 SQL 문자열 nito하지만 난 같은 그것을 왼쪽 테스트 목적으로 varibles를 추가 :

은 기본 폼 페이지에서 PHP입니다. 누구든지 도움이된다면 많은 도움이 될 것입니다.

+1

$ SQL1 =을 사용하는 경우이 쿼리

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

; 변경하십시오. – Dgo

+0

1) HTML로 삽입 할 때 값을 이스케이프 처리하지 않습니다. 2) mysql_query()가 성공했는지 확인하지 않는다. 3) 더 이상 사용되지 않는 확장 프로그램을 사용 중입니다. –

+0

Álvaro G. Vicario 그 지점까지 연장 할 수 있습니까? – user1284386

답변

0

사용하면 "SET 건강 = '건강 - 손상'ajax_demo UPDATE"

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

아, 고맙습니다. 많이 바뀌 었습니다. 이것이 지금 작동하지 않는 다른 이유는 무엇입니까? – user1284386

+0

@ user1284386 잘 작동하고 있습니다. 나는 시험했다. –

+0

빠른 답장을 보내 주셔서 감사합니다. 같은 양식을 통해 전화를 걸고 있습니까? BTN에서 action = attack.php를 클릭하십시오. – user1284386

관련 문제