I'm using this to insert songs that are submitted to my site:
The code works fine for users that have accounts but I get a white screen when guests attempt to submit songs.PHP Code:$insert_song = @mysql_query("SELECT artist_id, artist_name FROM artist ORDER BY artist_name ASC");
if(!@mysql_num_rows($insert_song))
{
die('You have to add at least one artist to the database first');
}
else
{
if($_POST['submit'] && strlen(trim($_POST['song_name'])))
{
$insert = mysql_query("INSERT INTO song SET
artist_id = '" . $artist_id . "',
song_name = '" . addSlashes($_POST['song_name']) . "',
song_features = '" . addSlashes($_POST['features']) . "',
song_lyrics = '" . addSlashes($_POST['song_lyrics']) . "',
song_contributer = '" . addSlashes($_POST['contributer']) . "',
song_status = 'inactive',
song_modified = NOW(),
song_dateadded = NOW(),
user_id = " . $_SESSION['user_id'] . "
");
$sql = ("INSERT INTO hits SET
song_hits=0, artist_id='" . $_POST['artist'] . "', song_id=" . mysql_insert_id() . ", song_hits_dateadded=now()");
if (@mysql_query($sql)) {
echo '';
} else {
echo '<p>Error submitting default hit value: ' .
mysql_error() . '</p>';
}
if($insert)
{
$submit = true;
}
else
{
die(mysql_error());
}
}
}
This is obviously happening because of this line:
Is there a way to write an if statement so that if a guest submits a song, the user_id will be blank?PHP Code:user_id = " . $_SESSION['user_id'] . "
Thank you.





Bookmarks