简体   繁体   中英

query won't update, using php pdo

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']));
        $appdetail->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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM