Forum Moderators: coopster

Message Too Old, No Replies

php / mssql query / Error

mssql_query executes sql statement, but still dies

         

milocold

12:00 am on Jul 31, 2007 (gmt 0)

10+ Year Member



Hi Guys,

So this is a beard scratcher. I'm having trouble using the INSERT and DELETE commands. SELECT works fine, but if I go to insert/delete a record, the T-SQL statement will execute fine but the die portion will still display.

Here's my code...

$str_SqlConn = mssql_connect ( '[i]ip info[/i]', '[i]uName[/i]', '[i]uPassword[/i]' ) or die ( 'Can not connect to server' );

mssql_select_db ( '[i]db name[/i]', $str_SqlConn ) or die ( 'Can not select database' );

$str_SqlDelete = "DELETE FROM tbl_cat WHERE cat_id = " . $_GET["removeId"];

mssql_query($str_SqlDelete) or die("Query Failed: " . $str_SqlDelete);

After the code runs I check SQL Query Analyzer and it shows the record has been removed, however the "Query Failed..." portion still shows and the page fails to continue processing.

Anyone experience this before? Or does anybody know where I can get the exact ms sql error printed to the screen versus the "Query failed" followed by the delete statement?

Specs:
--> No access to php.ini
--> Microsoft box
--> Shared Hosting Plan
--> PHP Version 4.3.10

Thanks for your time!

M. Cold

d40sithui

6:27 pm on Jul 31, 2007 (gmt 0)

10+ Year Member



well whenever the die command is executed, the script will stop processing from that moment on. personally, i havent used mssql (im a mysql guy) so i cant tell if there's something wrong with your syntax. i dont think there is since you say your select is working.

1)is it possible for you to go directly to to db using putty and check to see if the records are updated as what the Query Analyzer thingy says?
2)furthermore, in mysql theres a mysql_error() function that returns any errors. in mssql i dunno of any except for mssql_get_last_message() which returns the last message by the server. try that and see what happens

milocold

7:56 pm on Jul 31, 2007 (gmt 0)

10+ Year Member



*snip*

Thanks for your reply! I'm gonna look into a mssql_error funtion. =)

M .Cold

milocold

8:12 pm on Jul 31, 2007 (gmt 0)

10+ Year Member



Hi Fellas,

Well I couldn't find anything on a equivalent mssql function for mysql_error.

However, I did discover a new clue! If I comment out the:

"or die("Query Failed: " . $str_SqlInsertStmt);"

Portion, everything works great. So, I guess I've at least scored a new light to shine on this issue. =)

Thanks,

M. Cold