Help on my php submission page

A

Anonymous

Guest
try add {} in if statement
Code:
<?php 

if($_POST['submit']) 
{ 
include ('config.inc.php'); 
//Sanitize data 
$input['artist_name'] = mysql_real_escape_string($_POST['artist_name']); 
$input['lyric'] = mysql_real_escape_string($_POST['lyric']); 
$input['song_title'] = mysql_real_escape_string($_POST['song_title']); 
$input['gender'] = mysql_real_escape_string($_POST['gender']); 

$artist_check = "SELECT artist_id FROM artist WHERE artist_name LIKE '%". $input['artist_name'] ."%'"; 
if (mysql_num_rows($artist_check) == 0); // doesn't exist
{  // add this
  // do your first insert query 
  //Create query to insert data into artists table 
  $artist_query = "INSERT INTO artist (artist_name, gender) VALUES ('{$input['artist_name']}','{$input['gender' ]}')"; 
//Run query and exit if there is an error 
$artist_result = mysql_query($artist_query) or die('Error in artist query: ' . mysql_error()); 
} // add this
else 
{ // add this
// pull out the artist_id and call it $artist_id 
//Retrieve the number mysql assigned to the row just inserted 
$artist_id = mysql_insert_id(); 

}  // add this

// then do you your second query 

//Create query to insert lyrics 
$lyric_query = "INSERT INTO lyric (artist_id, song_title, lyric) VALUES ('{$artist_id}','{$input['song_title']}','{$input['lyric']}')"; 
//Run query and exit if there is an error 
$lyric_result = mysql_query($lyric_query) or die('Error in lyric query: ' . mysql_error()); 
} 
?>
[/quote]
 
oops sorry
Code:
<?php
if($_POST['submit']) 
{ 
include ('config.inc.php'); 
//Sanitize data 
$input['artist_name'] = mysql_real_escape_string($_POST['artist_name']); 
$input['lyric'] = mysql_real_escape_string($_POST['lyric']); 
$input['song_title'] = mysql_real_escape_string($_POST['song_title']); 
$input['gender'] = mysql_real_escape_string($_POST['gender']); 
$artist_check = "SELECT artist_id FROM artist WHERE artist_name LIKE '%". $input['artist_name'] ."%'"; 
if (mysql_num_rows($artist_check) == 0)
{ 	 
  $artist_query = "INSERT INTO artist (artist_name, gender) VALUES ('{$input['artist_name']}','{$input['gender' ]}')"; 

$artist_result = mysql_query($artist_query) or die('Error in artist query: ' . mysql_error()); 
}
else 
{
$artist_id = mysql_insert_id(); 
}
$lyric_query = "INSERT INTO lyric (artist_id, song_title, lyric) VALUES ('{$artist_id}','{$input['song_title']}','{$input['lyric']}')"; 
$lyric_result = mysql_query($lyric_query) or die('Error in lyric query: ' . mysql_error()); 
} 
?>
 
Back
Top