pbahmann1 pbahmann1 - 22 days ago 6
SQL Question

(PDO) UPDATE doesn't update with WHERE variable



My problem here is that as soon as i have WHERE with GuildName it does NOT work. It simply doesnt update anything at all.

As soon as i have the id=1 (there are 100 guilds, so setting the id=1 is not an option) it does work.

$form = $_POST;
$boss = $form['bossname'];
$gname = $form['guildname'];
$screen = $form['screenshot'];
$log = $form['logs'];
$defeat = $form['defeat'];

if(isset($_POST['edit-guild'])){

$Statement = $conn->prepare("UPDATE $boss SET `Bossname` =:boss, `GuildName` =:gname, `Screenshot` =:screen, `Link` =:link, `KillTime` =:defeattime, `KillYN` =:kill WHERE `GuildName`=:gname");
// EXECUTING ARRAY FOR ^GUILD INFORMATION
$Statement->execute(array(
"boss" => $boss,
"gname" => $gname,
"screen" => $screen,
"link" => $log,
"defeattime" => $defeat,
"kill" => 'Yes'
));
}


As soon as i have WHERE id=1 it does work.

$Statement = $conn->prepare("UPDATE $boss SET `Bossname` =:boss, `GuildName` =:gname, `Screenshot` =:screen, `Link` =:link, `KillTime` =:defeattime, `KillYN` =:kill WHERE id=1");

Answer

As mentioned you cant reuse the same param. Try giving it a different name:

if(isset($_POST['edit-guild'])){

    $Statement = $conn->prepare("UPDATE $boss SET `Bossname` =:boss, `GuildName` =:gname, `Screenshot` =:screen, `Link` =:link, `KillTime` =:defeattime, `KillYN` =:kill WHERE `GuildName`=:gname2");
    // EXECUTING ARRAY FOR ^GUILD INFORMATION
    $Statement->execute(array(
        "boss"          => $boss,
        "gname"         => $gname,
        "gname2"         => $gname,
        "screen"        => $screen,
        "link"          => $log,
        "defeattime"    => $defeat,
        "kill"          => 'Yes'
        ));
}