Hi Alfredo,

This looks like PHP - and we're on a MySQL list. Are you aware of the PHP lists - 
specifically PHP-DB?

Comments below:

> I'm new to mysql database design, I have a PHP script to DELETE records but
> before that I need to be sure that the record exists.
>
> My script goes like this:
>
> line 6 $var1 = " select * from table.field where id_record = '$record' ";
> line 7 if( $var2 = mysql_fetch_array($var1) )
> line 8 {
> line 9 deleting ...
> line 10 }
> line 11 else
> line 12 {
> line 13 record does not exit ...
> line 14 "It is not a valid record"
> line 15 }
>
> So when I test it with a record I know it doesn't exist, the script gives me
> the message ("It is not a valid record") and this : Warning: Supplied
> argument is not a valid MySQL result resource in
> c:\apache\htdocs\nuevo\icum\eliminar.php on line 7
>
> Any help will be appreciated

Between lines 6 and 7 issue a call to MySQL

You have the right idea with the logic - check that a row exists before issuing a 
DELETE instruction. A better
way to achieve it might be:

On line 7 use mysql_num_rows() to tell you how many/if any rows met the (WHERE) 
criteria - you're not actually
interested in having any data returned (to PHP).

However if you check out the DELETE command you will also see that it has a companion 
function called
mysql_affected_rows() which will advise how many rows, if any, were DELETEd and power 
the IF-errmsg
functionality thereafter.

Please RTFM Function Reference LXI. MySQL Functions particularly the MySQL_query(), 
MySQL_*_rows() and the
MySQL_Fetch_ functions.

You may also benefit from the many introductory tutorials - check out the Links at 
www.php.net.

Regards,
=dn



---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to