Jump to content


Photo

Simple truth check


  • Please log in to reply
1 reply to this topic

#1 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 01 October 2006 - 11:58 AM

Guys,

Just a quick one...  If I insert a row into my database using mysql_query() it returns TRUE if successful and FALSE if not.  I'm assigning this value to $insert...

$insert = mysql_query($sql) or die ("Couldn't execute $sql: " . mysql_error());

Now how do I check if $insert is true?  Do I just need to include it in my if statement like so...

if ($insert){ // my code...;}

I figured that even if $insert was FALSE, the fact that it's defined would still make the above statement true, is that correct?

Regards
Hungover Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#2 paul2463

paul2463
  • Members
  • PipPipPip
  • Advanced Member
  • 955 posts
  • LocationUK

Posted 01 October 2006 - 12:10 PM

you could always stipulate in the "if" statement what you want i.e
if($insert == true) {

do stuff

}

you cannot affect the past but you can ruin a perfectly good present by worrying about the future

*********************************************************************
The <A HREF="http://www.php.net/d...php">MANUAL</A> is actually a useful resource




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users