简体   繁体   中英

Mysql update command failing

Unbelievably, I have an exact script with a different variable than "additional" that works. However, even though there is a mysql column for additional, I can't get it to update. I have even tried changing additional to something else, yet it fails to work with this column. What is conflicting?

<?php
echo "yup";
$lt2 = "yup";
$blah = "yup";
$username = "yup";
$lt1 = "yup";
$dbh = new PDO(censored);
$sql = "UPDATE purchases SET additional = ? WHERE username = ? AND blah = ? AND kusername = ?";
$q = $dbh->prepare( $sql );
$params = array( $lt1, $lt2, $username, $blah );
$q->execute( $params );
$doc = new DOMDocument();
$r = $doc->createElement("location" );
$doc->appendChild( $r );
foreach ( $q->fetchAll() as $row) {
   $e = $doc->createElement( "location" );
    $e->setAttribute( 'name', $row['additional'] );


    $r->appendChild( $e );

}
print $doc->saveXML();

echo "work";
?>

try

$sql = "UPDATE purchases SET additional = ? WHERE username = ? AND blah = ? AND kusername = ?";
$q = $dbh->prepare( $sql );
$params = array( $lt1,$lt2, $username, $blah );

Can you please tell me this table has "auto increment" ID OR NOT.

If yes, Please pass the ID for which record you have updated.

$sql = "UPDATE purchases SET additional = '$lt1' WHERE purchase_id = ?";

If no, Please change query like this:

$sql = "UPDATE purchases SET additional = '$lt1' WHERE username = ? OR blah = ? OR kusername = ?";

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