Jump to content


Photo

DELETE works but wont throw back right result !


  • Please log in to reply
3 replies to this topic

#1 scratchwax2003

scratchwax2003
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 17 January 2003 - 04:42 PM

Please help...

have created this script to delete stuff from a database table and it works correctly, ie, only deletes if the right id number and password is submitted....BUT if the password or id is incorrect it still throws back the first IF message.

I have tried replacing the if ($Query) with if ($Result) and it still does the same thing.

here is the full page script:

<HTML>
<HEAD>
<TITLE> CREATING A DATABASE</TITLE>
</HEAD>
<BODY>

<?PHP

//trim the incoming data

$Array[Remove] = trim
($Array[Remove]);

$Array[IDRemove] = trim
($Array[IDRemove]);

//set the variables for the database connection:


$Host = \"localhost\";
$User = \"\";
$Password = \"\";
$DBName = \"\";
$TableName = \"\";

//have removed above info for obvious reasons!.

$Link = mysql_connect ($Host, $User, $Password);



$Query = \"DELETE FROM $TableName
WHERE Password = \'$Array[Remove]\'AND id= \'$Array[IDRemove]\'\";

$Result = mysql_db_query ($DBName, $Query, $Link);

if ($Query){
print(\"Please check to see if your item has been removed.<BR> If it still appears then either a wrong ID was used or your Password was incorrect.\");


} else {
print(\"no\");

}


mysql_close ($Link);

?>

<br><br>
<b><font size=\"2\" face=\"Arial, Helvetica, sans-serif\"><a href=\"DataBaseNonElectronic.php\">CHECK
IT NOW </a></font></b>
</body>
</html>

im on my knees with this one.... :?

#2 pallevillesen

pallevillesen
  • Members
  • PipPipPip
  • Advanced Member
  • 135 posts
  • LocationDenmark

Posted 17 January 2003 - 04:56 PM

You\'re testing if $query is defined... it is!

I think you should check $result instead....

:) EDIT: Woups.... didn\'t read the first lines of your post, sorry....

DELETE deletes rows from table_name that satisfy the condition given by where_definition, and returns the number of records deleted.  


so use
[php:1:a5aeea7a6e]

$Query = \"DELETE FROM $TableName
WHERE Password = \'$Array[Remove]\'AND id= \'$Array[IDRemove]\'\";

$Result = mysql_db_query ($DBName, $Query, $Link);

if ($Result > 0){
print(\"Success....\");
} else {
print(\"no\");

}
[/php:1:a5aeea7a6e]

P.
Palle Villesen, www.birc.dk [br]Bioinformatics Research Center

#3 scratchwax2003

scratchwax2003
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 17 January 2003 - 05:24 PM

thanks for the fast response...but i tried that and i keep getting the same result.

I am using phpTriad on my system for testing - do you think that it might be something to with that??

i am very baffled by this....

here is the piece i replaced:

$Link = mysql_connect ($Host, $User, $Password);


$Query =\"DELETE FROM $TableName
WHERE password = \'$Array[Remove]\' AND id = \'$Array[IDRemove]\'\";

$Result = mysql_db_query($DBName, $Query, $Link);


if ($Result > 0){
print(\"Success....\");
} else {
print(\"no\");

}
mysql_close($Link);
?>


please help again.... :(

#4 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 17 January 2003 - 07:19 PM

you could try mysql_affected_rows()
http://www.php.net/m...fected-rows.php
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users