You are here: Re: [PHP] Should this not return true?!?! « PHP « IT news, forums, messages
Re: [PHP] Should this not return true?!?!

Posted by Philip Hallstrom on 05/21/05 01:09

> Hi there (newbie here) - I have the following snippet of code......
>
> $sexId = $_POST['sex'];
> $fName = $_POST['fName'];
> $lName = $_POST['lName'];
>
> if ($status = $db->query("INSERT INTO names (nameId, sexId, fName, lName)
> VALUES ('', $sexId, '$fName', '$lName')")) {
> print "Your data was added to the database successfully!";
> } else {
> print "Your data could not be added to the database!";
> }
>
> Assuming my query was successful, should it not return true and print the
> success message?
>
> For some reason it is doing just the opposite. The data is added, but it
> displays the error instead.
>
> Am I misunderstanding something?

Hmmm... couple of things:

Your if statement isn't checking the value of '$status'. It's checking if
the assignment *to* $status is true or false. At least I think so.

So, I think at a minimum you want:

if ( $db->query.....

Also, what is $db->query supposed to return upon success? In the unix
world, programs typically return zero to indicate success and use other
values to differentiate b/n all the possible errors. if $db->query is
doing that, then that's the problem.

good luck.

-philip

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация