MySQL从一个表转到另一个表

时间:2015-10-02 13:55:56

标签: php mysql sql multiple-tables

嗨,我想知道是否有人可以提供帮助,我对MySQL非常陌生并努力让它做我想做的事情,我已经阅读了几个不同的帖子和网站,没有运气。 简短而简单,我的查询有问题。

    $a = $mysqli->real_escape_string($_POST['cardInputOne']);
            $b = $mysqli->real_escape_string($_POST['cardInputTwo']);
            $c = $mysqli->real_escape_string($_POST['cardInputThree']);
            $d = $mysqli->real_escape_string($_POST['cardInputFour']);

            $incomingCardNumber = "{$a}{$b}{$c}{$d}";
            $safeIncomingCard = $mysqli->real_escape_string($incomingCardNumber);
            $fundingUser = $mysqli->real_escape_string($email);

            $fundingQuery = "SELECT f.cardValue f.cardNumber FROM funding f 
WHERE f.cardNumber = '{$safeIncomingCard}' 
AND s.email, s.accountBalance FROM shopUser s 
WHERE s.email = '{$fundingUser}'" . 
"UPDATE s.accountBalance = s.accountBalance + f.cardValue";

2 个答案:

答案 0 :(得分:0)

如果您想根据另一个表中的数据更新表,那么您需要使用它的更新:

update shopUser, funding
set shopUser.accountBalance = shopUser.accountBalance + funding.cardValue
where shopUser.email='...' and funding.cardNumber='...'

php变量将取代...

答案 1 :(得分:0)

听起来像开启者想要用另一个数据更新表。 一般来说,这可能是:

UPDATE
  table1 AS target,
  (SELECT column1, column2 FROM table2) AS source
SET
  target.column3 = source.column1
WHERE
  target.column4 = source.column2

当然,您必须选择正确的源/目标列。