2011-11-18 48 views
0

我有我正在爲音樂評分的這個腳本,沒有錯誤,而且我得到'Data Inserted',我知道我還沒有逃脫數據,但是有沒有問題在這個腳本中可能會阻止它將插入的數據放入數據庫中?這不行?有什麼建議麼?

<? 
    include($_SERVER['DOCUMENT_ROOT'].'/assets/global/scripts/connect.php'); 
    $songname = $_GET['songname']; 
    $artist = $_GET['artist']; 
    $ratenum = 1; 
    $chkquery = "SELECT * FROM hotmuze_music WHERE songname='$songname'"; 
    $plusOneQuery = "SELECT * FROM hotmuze_music WHERE songname='$songname'"; 
    $updateQuery = "UPDATE hotmuze_music SET rating='$rating2' WHERE songname='$songname'"; 
    $checkdata = mysql_query($chkquery); 
    $checkrows = mysql_num_rows($checkdata); 
    if($checkrows==0) 
    { 
    $insquery = "INSERT INTO hotmuze_music (id, songname, artist, sex, genre, rating, promoted) VALUES('', '$songname', '$artist', '', '$genre' '$ratenum')"; 
    $insdata = mysql_query($insquery); 
    } 


    if($checkrows!=0) 
    { 
    $plusData = mysql_query($plusOneQuery); 
    } 

    if(mysql_num_rows($plusData)!=0) 
    { 
    $result = mysql_fetch_assoc($plusData); 
    $rating = $result['ratng']; 
    $rating2 = $rating+1; 
    mysql_query($updateQuery); 
    echo "Data Inserted"; 
    } 
    ?> 

謝謝! :)

+1

檢查錯誤:'mysql_foo()或死亡(mysql_error());'' – Blender

+0

$等級= $結果[「ratng '];'也許應該是'$ rating = $ result ['rating'];' – thetaiko

+0

你插入時沒有發送'升級'列值。 '$ Genre'之後也沒有昏迷 – HRgiger

回答

0

你得到Column count doesn't match value count at row 1的錯誤是由你的INSERT語句失蹤1個人更DB柱造成的。

(id, songname, artist, sex, genre, rating, promoted) 7個領域,你只給值6這是VALUES('', '$songname', '$artist', '', '$genre' '$ratenum')";

+0

非常感謝! :) – unicornication

1

你錯過了一個逗號,價值提升領域,以及嘗試:

 
$insquery = "INSERT INTO hotmuze_music (id, songname, artist, sex, genre, rating, promoted) VALUES('', '$songname', '$artist', '', '$genre', '$ratenum', '$promoted')"; 
+0

+1你是更快,然後我:) – HRgiger

+0

謝謝你:)儘管返回的錯誤是'列計數不匹配在第1行值計數',有任何想法嗎? :) – unicornication

1

您在腳本引用變量($rating2)的頂部定義$updateQuery其中尚未確定。嘗試最後一行改爲:

if(mysql_num_rows($plusData)!=0) 
{ 
    $result = mysql_fetch_assoc($plusData); 
    $rating = $result['rating']; 
    $rating2 = $rating+1; 
    mysql_query("UPDATE hotmuze_music SET rating='$rating2' WHERE songname='$songname'"); 
    echo "Data Inserted"; 
} 
+0

另請參閱@ Sudhir關於插入中缺少逗號的評論。 – thetaiko

+0

謝謝你:)雖然返回的錯誤是'列數不匹配第1行的值計數',有什麼想法嗎? :) – unicornication