ashleek007 Posted July 16, 2007 Share Posted July 16, 2007 Hi All, I'm running some queries to add information to a MS-SQL DB like this: - $new_page = "INSERT INTO **** (url, section, morder, mtext) VALUES ('$new_url_1', '$menu', '$menu_pos', '$mtext')"; $new_page_result = mssql_query($new_page); if (!$new_page_result) { $delete_content = "DELETE FROM **** WHERE cid = '$cid'"; $delete_result = mssql_query($delete_content); $domain="database-error.php?err=there was an error writing to the table"; header('Location:'. $domain); } The idea is to quit the SQL statement if an error occurs, delete everything that has happened before the statement and re-direct the user to an error page... For some reason it doesnt work though, and I have no idea why... any clues? Ash ??? Link to comment https://forums.phpfreaks.com/topic/60175-error-handling-php-and-mssql/ Share on other sites More sharing options...
ToonMariner Posted July 16, 2007 Share Posted July 16, 2007 try if (mssql_rows_affected() == 0) { Link to comment https://forums.phpfreaks.com/topic/60175-error-handling-php-and-mssql/#findComment-299390 Share on other sites More sharing options...
ashleek007 Posted July 16, 2007 Author Share Posted July 16, 2007 hey, this throws an error: - Warning: Wrong parameter count for mssql_rows_affected() in content-add-page-1.php on line 154 im trying to force the error... like this $new_content = "INSERTXXX INTO xxxx (content, title, menu_category, downloadonly) VALUES ('$content', '$mtext', '$menu', '0')"; $new_content_result = mssql_query($new_content); if (mssql_rows_affected() == 0) { $domain="database-error.php"; header('Location:'. $domain); } thanks for the help so far Ash Link to comment https://forums.phpfreaks.com/topic/60175-error-handling-php-and-mssql/#findComment-299400 Share on other sites More sharing options...
ToonMariner Posted July 16, 2007 Share Posted July 16, 2007 oh sorry you need to give the connection resource in the () Link to comment https://forums.phpfreaks.com/topic/60175-error-handling-php-and-mssql/#findComment-299404 Share on other sites More sharing options...
ashleek007 Posted July 16, 2007 Author Share Posted July 16, 2007 like this?.... if (mssql_rows_affected($new_content) == 0) { ... Link to comment https://forums.phpfreaks.com/topic/60175-error-handling-php-and-mssql/#findComment-299405 Share on other sites More sharing options...
ashleek007 Posted July 16, 2007 Author Share Posted July 16, 2007 sorry a different error still shows: - Warning: mssql_rows_affected(): supplied argument is not a valid MS SQL-Link resource with this... $new_content = "INSERTXXX INTO xxx (content, title, menu_category, downloadonly) VALUES ('$content', '$mtext', '$menu', '0')"; $new_content_result = mssql_query($new_content); if (mssql_rows_affected($new_content_result) == 0) { $domain="database-error.php"; header('Location:'. $domain); } Cheers, Ash Link to comment https://forums.phpfreaks.com/topic/60175-error-handling-php-and-mssql/#findComment-299416 Share on other sites More sharing options...
ToonMariner Posted July 16, 2007 Share Posted July 16, 2007 NO. You will have a resource for the connection - like $db = mssql_connect - it is that $db you will need to pass. Link to comment https://forums.phpfreaks.com/topic/60175-error-handling-php-and-mssql/#findComment-299457 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.