Need to run 3 queries.

This should be simple I just can’t figure out why it won’t work.

The first query works fine, no problems. Second and third work with the first one if they are used one at a time. What I’m trying to get is:

Enter information about a CD on a form.
Run query to find a match.
If match update number of copies by copies + 1. That works by itself first query.
If no match insert CD information into a new row. That works by itself with first query.
Tried in different order, checking if $reslt and if !$result. Tried if empty. Going to try isset next.
Been beating my head agaisnt a wall no luck. . .
Thanks in advance. BB

[php]

$artist = $_REQUEST [“artist”];
$altartist = $_REQUEST [“altartist”];
if (empty($altartist)){$altartist = $artist;}
$album = $_REQUEST [“album”];
$price = $_REQUEST [“price”];
$genre = $_REQUEST [“genre”];
$media = $_REQUEST [“media”];

        $sql =  "SELECT * FROM `music` WHERE
`artist/band` = '$artist' AND `album` 
= '$album'";

$result = mysql_query($sql);

if ($result) {$sql = mysql_query(“UPDATE music SET copies = copies + 1 WHERE artist/band = ‘$artist’ AND album = ‘$album’”)
or die(mysql_error());}

else{ $sql = mysql_query(“INSERT INTO music (artist/band, alt artist, album, price, copies, genre, media)
VALUES (’$artist’, ‘$altartist’, ‘$album’, ‘$price’, ‘1’, ‘$genre’, ‘$media’)”)
or die(mysql_error());}

mysql_free_result($result);

exit;[/php]

Hi bbarrett5150,

I don’t have access to my testing server at the moment, but give this a try:

[php]if(mysql_num_rows($result) > 0)[/php]
instead of[php]if ($result)[/php]

Fixed!

Thanks again, malasho .

Sponsor our Newsletter | Privacy Policy | Terms of Service