Jump to content

Recommended Posts

	<?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

<?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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.