Snooble Posted March 3, 2007 Share Posted March 3, 2007 <?php $sql = "SELECT * FROM songs WHERE Title = '".$_POST['songtitledelete']."' LIMIT 1"; mysql_query($sql) or die ("Couldn't execute $sql: " . mysql_error()); if (mysql_query($sql) == NULL){ echo "No such song"; } else { $sql2 = "DELETE FROM songs WHERE Title = '".$_POST['songtitledelete']."' LIMIT 1"; mysql_query($sql2) or die ("Couldn't execute $sql: " . mysql_error()); } ?> That should make sense? I want to check if the song is there. Otherwise it always says "Song Deleted". I want something to detect whether it's there before deleting the row. When i run it now i dont see "No such song" when i enter an invalid song name.. Thanks Snooble Quote Link to comment https://forums.phpfreaks.com/topic/41001-an-easy-mysql-check/ Share on other sites More sharing options...
papaface Posted March 3, 2007 Share Posted March 3, 2007 You should use mysql_num_rows instead. Quote Link to comment https://forums.phpfreaks.com/topic/41001-an-easy-mysql-check/#findComment-198539 Share on other sites More sharing options...
Snooble Posted March 3, 2007 Author Share Posted March 3, 2007 an example?? I assume, record the result before the sql and then after and if it's different then say successful else say "no song"? Snooble Quote Link to comment https://forums.phpfreaks.com/topic/41001-an-easy-mysql-check/#findComment-198542 Share on other sites More sharing options...
pocobueno1388 Posted March 3, 2007 Share Posted March 3, 2007 <?php $sql = mysql_query("SELECT * FROM songs WHERE Title = '".$_POST['songtitledelete']."'"); if (mysql_num_rows($sql) <= 0){ echo "No such song."; } else { mysql_query("DELETE FROM songs WHERE Title = '".$_POST['songtitledelete']."'"); echo "Successfully deleted song!"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/41001-an-easy-mysql-check/#findComment-198543 Share on other sites More sharing options...
Snooble Posted March 3, 2007 Author Share Posted March 3, 2007 i see, thank you! Very useful for me Quote Link to comment https://forums.phpfreaks.com/topic/41001-an-easy-mysql-check/#findComment-198544 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.