Jump to content


Photo

Checking for result of call to mssql_query()


  • Please log in to reply
1 reply to this topic

#1 stockton

stockton
  • Members
  • PipPipPip
  • Advanced Member
  • 319 posts
  • LocationMidrand South Africa

Posted 12 October 2006 - 12:25 PM

Am I misunderstanding the PHP Manual, where it says:-
mixed *mssql_query* ( string query [, resource link_identifier [, int batch_size]] )

Returns: A MS SQL result resource on success, *TRUE* if no rows were returned, or *FALSE* on error.

and my code reads:-

$insert = sprintf("INSERT INTO Users (FirstName, LastName, Usrname,Passwrd, AccessLevel, last_login,UserID)
                        VALUES ('%s', '%s', '%s', '%s', '%d', '%s', '%d')",
                            $FirstName, $Surname, $uname, $passwd,$accesslevel, $regdate, $_SESSION['UID']);
$Reply = mssql_query($insert, $link);
if ($Reply == FALSE)
        {
whether the query works or not I have yet to find $Reply equal to FALSE.
Please tell me what I am misunderstanding and what is the correct method  ????

Regards,
Alf Stockton   Programmer for rent.

#2 shivabharat

shivabharat
  • Members
  • PipPipPip
  • Advanced Member
  • 371 posts
  • LocationChennai, India

Posted 13 October 2006 - 04:42 PM

You dont have to explicitly check for true or false.

$insert = sprintf("INSERT INTO Users (FirstName, LastName, Usrname,Passwrd, AccessLevel, last_login,UserID)
                        VALUES ('%s', '%s', '%s', '%s', '%d', '%s', '%d')",
                            $FirstName, $Surname, $uname, $passwd,$accesslevel, $regdate, $_SESSION['UID']);
$Reply = mssql_query($insert, $link);
if ($Reply)
 {
     echo "Data Inserted";
}
else
{
   echo "Not Inserted";
}

Knowledge --- Reading Enriches Mind But Sharing Enhances It.[br][br]Note: Before you request help enusre that you have had a look at the tutorials @phpfreaks




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users