Jump to content

An easy mysql check.


Snooble

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.