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 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. 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 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!"; } ?> 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 Link to comment https://forums.phpfreaks.com/topic/41001-an-easy-mysql-check/#findComment-198544 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.