What about when DELETING from a table???  It always returns true.
Example...the highest ID in this table is 10:

if ($connection = mysql_connect("localhost","mysql","mysql")) {
        print "Connection established";
        $db = mysql_select_db("aanr", $connection);
        if ($sql = mysql_query("DELETE FROM bullitens WHERE id='1212'")) {
                print "Successful";
        else {
                print "Not successful.";
else {
        print "Connection NOT established.";

We try to delete the bulliten with id of 1212, but there is not bulliten
with that ID, and it says "Successful".

I know I could use mysql_affected_rows(), but why doesn't this work???


----- Original Message -----
From: "Mark Roedel" <[EMAIL PROTECTED]>
To: "Tyler Longren" <[EMAIL PROTECTED]>; "php-general"
Sent: Wednesday, July 18, 2001 1:30 PM
Subject: RE: [PHP] sql query successful

> -----Original Message-----
> From: Tyler Longren [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, July 18, 2001 1:25 PM
> To: php-general
> Subject: [PHP] sql query successful
> I've been writing database enabled site for quite a while
> now.  One thing I have never figured out it how to determine
> if a sql query is successful.
> This works:
> if ($connection = mysql_connect("host","username","password")) {
>     print "Successful connection":
> }
> else {
> print "No connection";
> }
> But this won't work:
> if ($sql = mysql_query("SELECT * FROM table ORDER BY rand()")) {
>     print "SQL executed successfully.";
> }
> else {
>     print "SQL not executed successfully.";
> }

In what way doesn't this work?

The above code should tell you that the query was properly formed and
error-free, and was cheerfully accepted and processed by the database
server.  (You don't get much more successful than that...)

If what you're really looking for is whether there were any rows
returned by the query, then you'll want to look into the
mysql_num_rows() function.

Mark Roedel ([EMAIL PROTECTED])  ||  "There cannot be a crisis next week.
Systems Programmer / WebMaster  ||   My schedule is already full."
     LeTourneau University      ||                    -- Henry Kissinger

PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to