Re: IBM's Learning PHP Part 1 tutorial.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Bill I like doing a switch statement base on the returned count from the 
query. I feel this gives me better control over the output. keep in mind 
that you can not use mysql_num_rows() with anything but a select statement. 
also you would turn off error reporting in the ini file since this is a 
system to replace that.
example
$query = "select userLvl from users where userName='".$_POST['userName']."'"
$result = mysql_query($query,$conn);
$ttlReturned = mysql_num_row($result);
switch($ttlReturned)
{
   case -1:
       // db error. process this and fail gracefully
       break;
   case 0:
       // no results returned. enter the new user
       break;
   case 1:
       // one record found. return a notice to the user the name exist
       break;
   default:
       // this would be a catch all for more than one record found. This may 
record a        // message to be sent to the db admin to correct, if you 
only want one user            // with this name.
}
// continue script with result from above.....

Chris

"Bill McEachran" <billmc@xxxxxxxxxxxxxxx> wrote in message 
news:42CB4399.7030303@xxxxxxxxxxxxxxxxxx
> Newbie question.
>
> I'm working my way through IBM's PHP tutorial.  Generally good ... but I'm 
> stuck at an error point and have no idea what's going wrong.
> Before adding a new row to the mysql database (already opened) we do a 
> query to see if a particular record already exists.
> (see $resultT).
>
> We then test, using if, to see if $resultT is true or false.  If it's 
> false we are then supposed to enter a new record.
> Problem: it's never false.   It always evaluates true.  What am I doing 
> wrong?   TIA
>
> /*   build query to see if the record is entered already */
>     $sqlT = "select * from users where username='".$_POST["name"]."'";
>     $resultT = mysql_query($sqlT);
>
> /*   Now test -- did we find anything ... if not add this user */
>     if (! $resultT) {
> /*  here we add the new record if it doesn't already exit /* 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux