Thanks for your time @droopsnoot, I have try to follow what you say but am getting this error message from the CATCH…
error getting recharge card info: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘FROM mtn_n100 WHERE id = ‘12’’ at line 1
the script am running is below…help me find out what am doing wrong, after buy I want the numbers thats was buy to be deleted from the table and also get it insert to the history table so that I can display it to the User via their member Id…I check the history table in the database and everything is inserted there but the number do not get deleted from it own table (mtn_n100) and I get the error message above…
$buyMtnId = $_POST['id'];
if (isset($_POST['action']) and $_POST['action'] == 'Buy Now') {
try
{
require database.php';
$sql= "SELECT id, pinNumber, serialNumber FROM mtn_n100 WHERE id = :id";
$s = $pdo->prepare($sql);
$s->bindValue(':id', $buyMtnId, PDO::PARAM_STR);
$s->execute(); // Execute the prepared query.
foreach ($s as $row) {
$buyMtn100s[] = array( 'id' =>$row['id'], 'pinNumber' =>$row['pinNumber'], 'serialNumber' =>$row['serialNumber']);
}
foreach ($buyMtn100s as $buyMtn100)
$buyMtnuserId = $buyMtn100['id'];
$mtn100 = 100;
if($accountBal == $mtn100 or $accountBal > $mtn100) {
$buyMtnPinNumber = $buyMtn100['pinNumber'];
$buyMtnPinSerialNumber = $buyMtn100['serialNumber'];
require $_SERVER['DOCUMENT_ROOT'] . '/includes/updateMTN.inc.php';
$currentBal = $accountBal - $mtn100;
$sql = 'UPDATE mem SET accountBal = :accountBal WHERE id =:id';
$s = $pdo->prepare($sql);
$s->bindValue(':id', $_SESSION['userId'], PDO::PARAM_STR);
$s->bindValue(':accountBal', $currentBal, PDO::PARAM_STR);
$s->execute(); // Execute the prepared query.
}
if($s) {
require database.php';
$sql = ' INSERT INTO history SET
buyerId =:buyerId,
buyerPhoneNumber =:buyerPhoneNumber,
pinId =:pinId,
pinNumber =:pinNumber,
pinSerialNumber =:pinSerialNumber,
buyDateTime = NOW() ';
$historyStmt = $pdo->prepare($sql);
$historyStmt->bindValue(':buyerId', $_SESSION['userId'], PDO::PARAM_STR);
$historyStmt->bindValue(':buyerPhoneNumber', $_SESSION['phoneNumber'], PDO::PARAM_STR);
$historyStmt->bindValue(':pinId', $buyMtnuserId, PDO::PARAM_STR);
$historyStmt->bindValue(':pinNumber', $buyMtnPinNumber, PDO::PARAM_STR);
$historyStmt->bindValue(':pinSerialNumber', $buyMtnPinSerialNumber, PDO::PARAM_STR);
$historyStmt->execute(); // Execute the prepared query.
}
if($historyStmt) {
require database.php';
$sql= "DELETE id, FROM mtn_n100 WHERE id = :id";
$s = $pdo->prepare($sql);
$s->bindValue(':id', $buyMtnuserId, PDO::PARAM_STR);
$s->execute(); // Execute the prepared query.
}
else {
$lowBal = 'Your account balance is too low, kindly add fund';
}
catch (PDOException $e)
{
echo "error getting recharge card info: " . $e->getMessage();
// include 'error.html.php';
exit();
}
}
I will be very happy to hear from you real soon. thanks so much for been there.