开发者

query won't update, using php pdo

开发者 https://www.devze.com 2023-04-13 02:39 出处:网络
My first query is this: $sql = \"UPDATE application SET userid = ? WHERE appid = ? LIMIT 1\"; My second query is this:

My first query is this:

$sql = "UPDATE application SET userid = ? WHERE appid = ? LIMIT 1";

My second query is this:

SELECT user.name,application.appid,application.userid,application.created,application.title,application.filesize,application.status,application.apptype 
FROM user,application 
WHERE application.appid = ? LIMIT 1

Then the second query is stored using $statement->fetchObject()

The problem is that $statement->name is always bob. application.userid is a foregin key to userid in table user. If I change the userid in table application, lets say 10, query 2 should get the name from the table user on the new userid, but the problem is that it keeps telling me that $statement->name is bob.

if (isset($_POST['newowner']))
{
    $newowner = $_POST['newowner'];
    $sql = "SELECT COUNT(*) FROM user 
            WHERE userid = ? LIMIT 1";
    $statement = $db->prepare($sql);
    $statement->execute(array($newowner));

    if ($statement->fetchColumn() > 0)
    {
        $sql = "UPDATE application SET userid = ? 
                WHERE appid = ? LIMIT 1";
        $statement = $db->prepare($sql);
        $statement->execute(array($newowner,$_GET['appid']));
        $appd开发者_开发问答etail->msg = "Owners were successfully changed.";
        $appdetail->type = "success";
    }
    else
    {
        $appdetail->msg = "Could not find client by that userid or email.";
        $appdetail->type = "warning";
    }
}
$sql = "SELECT user.name,application.appid,application.userid,application.created,application.title,application.filesize,application.status,application.apptype 
        FROM user,application 
        WHERE application.appid = ? LIMIT 1";
$statement = $db->prepare($sql);
$statement->execute(array($_GET['appid']));
$app = $statement->fetchObject();


Using PDO you should be able to determine how many rows are affected by the UPDATE. Check that this corresponds to the number of rows you expect to be modified in your test data. Edit: this is the statement you'll need.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号