I'm trying to update a row in mysql using PDO
to do so, i have no idea why it doesn't execute. Everything seems to be correct, but it doesn't execute, neither does it generates any error.
First i get the values that i send via $.ajax
$idRequest = $_POST['idRequest'];
$dateStarted = $_POST['dateStarted'];
$requester = $_POST['requester'];
$quantity = $_POST['quantity'];
$qaauthorization = $_POST['qaauthorization'];
$qengineer = $_POST['qengineer'];
$performer = $_POST['performer'];
$voltage = $_POST['voltage'];
$goal = $_POST['goal'];
$measurementunit = $_POST['measurementunit'];
$account = $_POST['account'];
$centercost = $_POST['centercost'];
$ela = $_POST['ela'];
$it = $_POST['it'];
$testtype = $_POST['testtype'];
$brand = $_POST['brand'];
$model = $_POST['model'];
$part = $_POST['part'];
$objective = $_POST['objective'];
$production = $_POST['production'];
$reason = $_POST['reason'];
$specifications = $_POST['specifications'];
Then i create the query
$queryRQ = "UPDATE
request
SET
`idRequester` = ? , `idQEngineer` = ? , `RequestDate` = ? , `idModelNumber` = ?,`idPartDescription` = ? ,`idTestType` = ? , `ReasonForTesting` = ? ,
`Quantity` =?,`Goal` = ?,`idMeasurementUnit` = ?, `Voltage` = ?, `AccountNumber` = ?, `CenterCost` = ?, `ELA` = ?,`ITNumber` = ?, `idPerformer` = ?, `DateStarted` = NOW(), `DateCompleted` = NULL,
`Specifications` =?, `idObjective` = ?, `idProduction` = ?, `idBrand` = ?, `Available` = 1 , `Pending` = 0)
WHERE
idRequest = ?";
Finally when i prepare
and execute
the $stmt
it seems as if nothing has happened, and it doesn't generate any error
$reqVals = array($requester,$qengineer,$dateStarted,$model,$part,$testtype,$reason,
$quantity,$goal,$measurementunit,$voltage,$account,$centercost,$ela,$it,$performer,
$specifications,$objective,$production,$brand, /* WHERE */ $idRequest);
$stmtRQ = $pdo->prepare($queryRQ);
$stmtRQ->execute($reqVals);
I'm reporting the error by surrounding everything with a try - catch
:
try{
// EVERYTHING
} catch(PDOException $e){
echo(json_encode($e->getMessage());
}
You have an extra NULL keyword which looks out of place...
`DateStarted` = NOW(), NULL,
^^^^^
There's also a right paren that looks invalid ...
`Pending` = 0)
^
For spotting these kinds of things, formatting SQL statements in a particular way (even if it is more lines) helps a lot... here's a malformed SQL statement that is equivalent to yours, it has the extraneous NULL keyword, and the unmatched closing (right) paren:
UPDATE request
SET `idRequester` = ?
, `idQEngineer` = ?
, `RequestDate` = ?
, `idModelNumber` = ?
, `idPartDescription` = ?
, `idTestType` = ?
, `ReasonForTesting` = ?
, `Quantity` = ?
, `Goal` = ?
, `idMeasurementUnit` = ?
, `Voltage` = ?
, `AccountNumber` = ?
, `CenterCost` = ?
, `ELA` = ?
, `ITNumber` = ?
, `idPerformer` = ?
, `DateStarted` = NOW()
, NULL
, `Specifications` = ?
, `idObjective` = ?
, `idProduction` = ?
, `idBrand` = ?
, `Available` = 1
, `Pending` = 0
)
WHERE idRequest = ?
If this SQL statement is being sent to the database, the database is certainly raising an exception. The more fundamental problem is that your code is either not preparing this statement, or it's not exposing a SQL exception in the way you expect it to.
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.