Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query screwyness

Status
Not open for further replies.

irbk

MIS
Oct 20, 2004
578
US
Have the following code....
Code:
$query = "UPDATE tablename SET title='$title', content='$cont' WHERE contentid='$cid'";
$result = mssql_query ($query);
if ($result){
  echo '<p>Database updated</p>';
} else {
  echo $query;
}
Here is the screwy thing. It updates the database correctly, however, $result for some reason is still coming back false so the $query is printed to the screen. Any ideas why?

Thanks in advance.
 
possibly a type comparison problem?

does this bode any better for you?

Code:
if ($result === false){
  echo $query;
} else {
  echo '<p>Database updated</p>';
}



*cLFlaVA
----------------------------
[tt]( <P> <B>)13 * (<P> <.</B>)[/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
PHP version is 4.3... though I guess the bug could have existed in 4.3 as well.

I get the same results if I try the different comparision. $result still returns as false even though the database is updated.
 
must buy glasses, apologies.

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
KarveR,
It's not that $query isn't saying that it failed, it's saying it always fails even though it does run sucessfully. I'll look into the mssql_rows_affected() function. I suppose as long as it returns 1 row, I can assume that it ran $query sucessfully.

Thanks all for your posts.
 
To keep your existing code, I'd check in that case:

if ($result =='0'){
echo '<p>Database updated</p>';
} else {
echo $query;
}

as Im pretty sure it will return 0 on success (which meets the fail criteria in your if statement) and anything other for fail.

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
KarveR -
That seemed to do the trick. Altho, I didn't try to input a bad query to see if it dies correctly..... But it at least seems to return the correct info if it runs correctly.... Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top