这个php查询应该像其他的一样运行。 看不出我的错误

这个php查询应该像其他的一样运行。 看不出我的错误

问题描述:

This query runs when I comment out the code above '}else{'. Have done so many like it and way more complex but I can't see where I'm tripping up.

(The page won't run like a syntax mistake. all vars match table)

Thanks. Allen

if ($version == 'prem'){

    $sql ="SELECT * FROM artistInfo WHERE user_id = '$user_id' AND artist_name = '$artist_name' ";
    $res = mysql_query($sql);
    $num = mysql_num_rows($res);
    if($num>0){
           while($row = mysql_fetch_array($res)){ 
             $artist_id = $row['artist_id'];

        } else {

mysql_query("INSERT INTO artistInfo (user_id, artist_name) VALUES ('$user_id', '$artist_name')");
$row_num = mysql_insert_id();    
$artist_id = $user_id."-".$row_num;      

mysql_query("UPDATE artistInfo SET artist_id = '$artist_id' WHERE row_num = '$row_num'  ");

     }
    }

} 

I think that your last bracket got misplaced. you will also need to move the last } just before else

if ($version == 'prem'){

    $sql ="SELECT * FROM artistInfo WHERE user_id = '$user_id' AND artist_name = '$artist_name' ";
    $res = mysql_query($sql);
    $num = mysql_num_rows($res);
    if($num>0){
           while($row = mysql_fetch_array($res)){ 
             $artist_id = $row['artist_id'];
            }

    } else {

mysql_query("INSERT INTO artistInfo (user_id, artist_name) VALUES ('$user_id', '$artist_name')");
$row_num = mysql_insert_id();    
$artist_id = $user_id."-".$row_num;      

mysql_query("UPDATE artistInfo SET artist_id = '$artist_id' WHERE row_num = '$row_num'  ");

     }
}

You're missing the closing } for the while loop.

missing } for while loop

 if($num>0){
           while($row = mysql_fetch_array($res)){ 
             $artist_id = $row['artist_id'];

        } 
    }
    else {