PHP Update query

PHP Update query

am 03.11.2009 06:59:34 von Ron Piggott

--=-nC6baOS/wqkoA6Q4gGZA
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

How do I test if an UPDATE query worked

$query = "UPDATE `clients` SET `company` = '$company', `contact` =
'$contact', `phone` = '$phone', `city` = '$city' WHERE
`clients`.`reference` =$client LIMIT 1";
$client_result=mysql_query($query);

???

Ron

--=-nC6baOS/wqkoA6Q4gGZA--

Re: PHP Update query

am 03.11.2009 07:09:05 von dmagick

Ron Piggott wrote:
> How do I test if an UPDATE query worked
>
> $query = "UPDATE `clients` SET `company` = '$company', `contact` =
> '$contact', `phone` = '$phone', `city` = '$city' WHERE
> `clients`.`reference` =$client LIMIT 1";
> $client_result=mysql_query($query);
>
> ???

http://www.php.net/manual/en/function.mysql-affected-rows.ph p

If it returns 0 that could mean:
- no row was originally found with that condition
or
- no update was performed (the data stayed the same)

--
Postgresql & php tutorials
http://www.designmagick.com/


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: PHP Update query

am 03.11.2009 07:11:38 von Yves Sucaet

Hi Ron,

Have a look at http://www.php.net/manual/en/function.mysql-info.php

----- Original Message -----
From: "Ron Piggott"
To: "PHP DB"
Sent: Monday, November 02, 2009 11:59 PM
Subject: [PHP-DB] PHP Update query


> How do I test if an UPDATE query worked
>
> $query = "UPDATE `clients` SET `company` = '$company', `contact` =
> '$contact', `phone` = '$phone', `city` = '$city' WHERE
> `clients`.`reference` =$client LIMIT 1";
> $client_result=mysql_query($query);
>
> ???
>
> Ron
>


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: PHP Update query

am 03.11.2009 07:15:06 von Sudheer Satyanarayana

On Tuesday 03 November 2009 11:29 AM, Ron Piggott wrote:
> How do I test if an UPDATE query worked
>
> $query = "UPDATE `clients` SET `company` = '$company', `contact` =
> '$contact', `phone` = '$phone', `city` = '$city' WHERE
> `clients`.`reference` =$client LIMIT 1";
> $client_result=mysql_query($query);
>
> ???
>
> Ron
>
>
From the manual page:

"For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc,
*mysql_query()* returns *TRUE* on success or *FALSE* on error. "

If $client_result == true you know the query was successful.


--

With warm regards,
Sudheer. S
Tech stuff: http://techchorus.net
Business: http://binaryvibes.co.in


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: PHP Update query

am 04.11.2009 18:20:54 von Jason Gerfen

$query = "UPDATE `clients` SET `company` = '$company', `contact` =
'$contact', `phone` = '$phone', `city` = '$city' WHERE
`clients`.`reference` =$client LIMIT 1";
$client_result=mysql_query($query);

// now check for errors
mysql_error() & mysql_errno()

Sudheer Satyanarayana wrote:
> On Tuesday 03 November 2009 11:29 AM, Ron Piggott wrote:
>> How do I test if an UPDATE query worked
>>
>> $query = "UPDATE `clients` SET `company` = '$company', `contact` =
>> '$contact', `phone` = '$phone', `city` = '$city' WHERE
>> `clients`.`reference` =$client LIMIT 1";
>> $client_result=mysql_query($query);
>>
>> ???
>>
>> Ron
>>
>>
> From the manual page:
>
> "For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc,
> *mysql_query()* returns *TRUE* on success or *FALSE* on error. "
>
> If $client_result == true you know the query was successful.
>
>


--
Jason Gerfen
Systems Administration/Web application development
jason.gerfen@scl.utah.edu

Marriott Library
Lab Systems PC
295 South 1500 East
Salt Lake City, Utah 84112-0806
Ext 5-9810


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: PHP Update query

am 05.11.2009 13:24:53 von David Robley

Jason Gerfen wrote:

> $query = "UPDATE `clients` SET `company` = '$company', `contact` =
> '$contact', `phone` = '$phone', `city` = '$city' WHERE
> `clients`.`reference` =$client LIMIT 1";
> $client_result=mysql_query($query);
>
> // now check for errors
> mysql_error() & mysql_errno()
>
> Sudheer Satyanarayana wrote:
>> On Tuesday 03 November 2009 11:29 AM, Ron Piggott wrote:
>>> How do I test if an UPDATE query worked
>>>
>>> $query = "UPDATE `clients` SET `company` = '$company', `contact` =
>>> '$contact', `phone` = '$phone', `city` = '$city' WHERE
>>> `clients`.`reference` =$client LIMIT 1";
>>> $client_result=mysql_query($query);
>>>
>>> ???
>>>
>>> Ron
>>>
>>>
>> From the manual page:
>>
>> "For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc,
>> *mysql_query()* returns *TRUE* on success or *FALSE* on error. "
>>
>> If $client_result == true you know the query was successful.
>>
>>
>
>
Those solutions will tell you if the query had no syntax errors. It won't
tell you if any rows were updated. As was mentioned by others, the solution
is mysql_affected_rows() which will "Get the number of affected rows by the
last INSERT, UPDATE, REPLACE or DELETE query"



Cheers
--
David Robley

Echo Trek: To boldly go off-topic where &#*@^$ NO CARRIER
Today is Prickle-Prickle, the 17th day of The Aftermath in the YOLD 3175.


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php