Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a database with table users. I need to update the table.

The code below works where 'send' is a user name in the row user_name

Code:
PHP
$query_new_user_update = $pdo->prepare("UPDATE users set user_balance = :user_balance where user_name = 'send'");

However I need 'send' to be a variable like below
PHP
$user = 'send';


However code below does not work.

Code:
PHP
$pdo = new PDO('mysql:host='. $host .';dbname='.$db_test, $db_username, $db_password);
        

$query_new_user_update = $pdo->prepare("UPDATE users set user_balance = :user_balance where user_name = :user");
$query_new_user_update->bindValue(1,':user_balance', $ubalance, PDO::PARAM_STR);
$query_new_user_update->bindValue(2,':user', $user, PDO::PARAM_STR);
$query_new_user_update->execute();
Posted
Updated 24-Dec-13 12:44pm
v3

1 solution

Trying changing this:
SQL
$query_new_user_update->bindValue(1,':user_balance', $ubalance, PDO::PARAM_STR);
$query_new_user_update->bindValue(2,':user', $user, PDO::PARAM_STR);
$query_new_user_update->execute();

to
SQL
$params = array(':user_balance' => $ubalance,  ':user' => $user);
$query_new_user_update->execute($params);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900