Jump to content

error handling PHP and MSSQL


ashleek007

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.