2013-03-08 2 views
-5

이 내 PHP 코드 지금까지mysql_fetch 반환 정의되지 않은 값

<?php 
    $con=mysqli_connect("host","user","pass","db_name"); 
    // Check connection 
    if (mysqli_connect_errno()) 
    { 
    echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
    } 
    $result_set = mysqli_query($con,"SELECT points FROM total WHERE id = 1"); 
    $row = mysql_fetch($result_set); 
    $old_total = $row['total']; 
    $new_total = $old_total + $_REQUEST['total']; 
    mysqli_query($con,"UPDATE total SET points = $new_total WHERE id = 1"); 
    mysqli_close($con); 
    ?> 

입니까?

답변

2

대신 mysqli_fecth_array/assoc를 사용하여 $ row [ 'total']의 코드 아래

시도 :

<?php 
$con=mysqli_connect("host","user","pass","db_name"); 
// Check connection 
if (mysqli_connect_errno()) 
{ 
echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
} 
$result_set = mysqli_query($con,"SELECT points FROM total WHERE id = 1"); 
$row = mysqli_fetch_assoc($result_set); 
$old_total = $row['points']; 
$new_total = $old_total + $_REQUEST['total']; 
mysqli_query($con,"UPDATE total SET points = $new_total WHERE id = 1"); 
mysqli_close($con); 
?> 
2

mysql_fetch 대신 mysqli_fetch이어야합니다.

1

당신은 ......

$row = mysqli_fetch_assoc($result_set); 

istead

$row = mysqli_fetch($result_set); 

의 사용이 유용 할 것이다 희망이

당신은 $ 행 [ '포인트']를 사용한다
+0

... 덕분에 모든 : '$ RESULT_SET = mysqli_query ($ 콘 " SELECT 지점에서 전체 WHERE id = 1 "); $ row = mysqli_fetch_assoc ($ result_set); $ old_total = $ row [ 'points']; $ new_total = $ old_total + $ _REQUEST [ 'total']; mysqli_query ($ con, "UPDATE 총 SET 포인트 = $ new_total WHERE id = 1"); mysqli_close ($ con); ?>' – user2125726

0

최종 코드 : 내가 올바른 코드를 얻기 위해 3 개 답변을 혼합

$result_set = mysqli_query($con,"SELECT points FROM total WHERE id = 1"); 
$row = mysqli_fetch_assoc($result_set); 
$old_total = $row['points']; 
$new_total = $old_total + $_REQUEST['total']; 
mysqli_query($con,"UPDATE total SET points = $new_total WHERE id = 1"); 
mysqli_close($con); 
?>