rahules rahules - 1 year ago 73
PHP Question

PHP PDO UPDATE table not working

I'm using the PHP PDO's to insert and update values in a table.
The insertion works fine. But when i try to update, nothing happens.
I get no errors, no exceptions.

the code is

$sql="UPDATE customers SET Name=:name,Company=:company,Address=:address,City=:city,State=:state,Country=:country,MainP=:phonem,CellP=:phonec,Email=:email,Action=:action WHERE CompanyID=:cid";

and the rest:

$stmt = $dbh->prepare($sql);
echo $stmt->rowCount();

So, is there something I am doing wrong?

EDIT: Forgot to mention that i am getting a row count of 0. And I've tried without the quotes. It still doesnt work

EDIT: Just found out that customer_id is being returned as 0 froma nother function.
Thanks for the help.

Answer Source

May be there is no data that query can update ,when using strings like name in query ,try giving like & % to be safe(there may be empty spaces if not taken care off while inseting)


WHERE Name like '%name%";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download