I have an isssue with my if else statement

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Post Reply
seandisanti
php-forum Fan User
php-forum Fan User
Posts: 973
Joined: Mon Oct 01, 2012 12:32 pm

Re: I have an isssue with my if else statement

Post by seandisanti » Thu Apr 10, 2014 4:34 pm

You should look into PDO for database interactions, it's more secure, and performs better, and is not any harder to implement. That said, what is the output you're getting?

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 973
Joined: Mon Oct 01, 2012 12:32 pm

Re: I have an isssue with my if else statement

Post by seandisanti » Fri Apr 11, 2014 12:45 am

Look at your logic. specifically this part.
$retval = mysql_query( $query, $conn );
if($retval )
{
die('Could not delete data: ' . mysql_error());

}
mysql_query() for a delete statement returns true upon success. But you're reporting fail for true response, and success otherwise. Hence the false positive. Fix your logic and you should get some helpful output as to why the record isn't being deleted. The documentation for the function is at http://us2.php.net/manual/en/function.mysql-query.php and it starts with the same warning about using deprecated libraries that my first response did.

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 973
Joined: Mon Oct 01, 2012 12:32 pm

Re: I have an isssue with my if else statement

Post by seandisanti » Fri Apr 11, 2014 5:57 pm

That was your code i posted, and it only announces failure upon success.

you have 'if($retval)' should be if( ! $retval)

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest