Jump to content

[SOLVED] Understanding documentation on mssql_query


stockton

Recommended Posts

The documentation says & I quote

 

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

 

and I really do not understand what I should do to ensure that the SQL INSERT was successful.

My code looks like:-

$SQL = sprintf("INSERT INTO TicketsIssued (Date, EventID, MemberNumber, EarnType, NumTicketsIssued, Turnover, UserID)
               VALUES ('%s', '%d', '%s', '%s', '%d', '%d', '%d')",
                   $Datum, $Event, $MemberNum, $EarnType, $BonusValue-$BonusIssued, 0, $_SESSION['UID']);

$rs = mssql_query($SQL, $link);

if ($rs===FALSE)

Will $rs be TRUE, FALSE or something else on successful completion?

Your code will work. If you do a boolean comparison on the variable and it has the successful resource in it, it should return true too. A common method is using or after the statement, which will execute if the function returns false.

$rs = mssql_query($SQL, $link) or die ("error message: " . mssql_get_last_message());

Thank you for your reply.

What I really need to do is keep two tables in the same database in step by using two SQL INSERT statements and check after each that the INSERT commands succeeded and if not back out the database.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.