这不行吗?有什么建议?

时间:2011-11-18 03:57:20

标签: php mysql

我有这个脚本我正在努力评价音乐,没有错误,我正在'数据插入',我知道我还没有逃过数据,但有没有此脚本中可能阻止它将插入的数据放入数据库的问题?

 <?
    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";
    } 
    ?>

谢谢! :)

3 个答案:

答案 0 :(得分:1)

你错过了一个逗号,也提到了推广字段的价值,试试:

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

答案 1 :(得分:1)

您可以在脚本顶部定义$updateQuery,引用尚未定义的变量($rating2)。尝试将最后一行更改为:

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";
} 

答案 2 :(得分: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')";