rahules rahules - 1 month ago 11
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);
$stmt->bindParam(":name",$name);
$stmt->bindParam(":company",$company);
$stmt->bindParam(":cid",$customer_id);
$stmt->bindParam(":address",$address);
$stmt->bindParam(":city",$city);
$stmt->bindParam(":state",$state);
$stmt->bindParam(":country",$country);
$stmt->bindParam(":phonem",$main_num);
$stmt->bindParam(":phonec",$cell_num);
$stmt->bindParam(":email",$email);
$stmt->bindParam(":action",$action);
$stmt->execute();
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

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)

example

WHERE Name like '%name%";