How can I delete a row I want to display? I want 2 display the row and then delete it

any idea is welcome…the things is that I have a number store in the database and I get it display on the page like this 008******************, so when the user click a button like buy the page will load and display the number in full 0088643435355, so now I dont want another user to see the same number cause one user already pay for it and it should be remove from the database…the number as to be display in full for the user who buy it so that they can make use of it, so another user dont have to buy same number…

I have try it but am getting error message that say…

SQLSTATE[42S02]: Base table or view not found: 1109 Unknown table ‘id’ in MULTI DELETE

help me find out what am doing wrong…


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 members 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.


include $_SERVER['DOCUMENT_ROOT'] . '/includes/insertUserDB.inc.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.

require $_SERVER['DOCUMENT_ROOT'] . '/includes/deleteMTN.inc.php';
$sql= "DELETE id FROM mtn_n100 WHERE id = :id";
$s = $pdo->prepare($sql);
$s->bindValue(':id', $buyMtnId, PDO::PARAM_STR);
$s->execute(); // Execute the prepared query.
==============================
echo $buyMtnPinNumber;
echo $buyMtnPinSerialNumber;

 

error message
SQLSTATE[42S02]: Base table or view not found: 1109 Unknown table ‘id’ in MULTI DELETE

DELETE FROM mtn_n100 WHERE id = :id"

Don’t specify the column names after DELETE. You don’t delete certain columns, you delete entire rows.

thanks @guido2004…everything works fine now…there is one thing I will like to do, when I click the buy button the page will load and display the number in full and also delete it from the database but is still appear on the page when the page return with the full number. until I refresh the page before it get disappear, I hope to delete it while the page reload without needing to refresh cause I think some user might click the buy for the same number again but get error which I try myself…

Sorry, you’ve lost me here. I don’t understand what you’re trying to say or do.

To make the database update, you will probably need AJAX.
Then a hide div (javaScript) to hide the div the number is in.

thanks @guido…I have try to fix it and everything is working fine now…

another things am trying to do now it that I want to include html tags when I want to output but I have my value in htmlspecialchars($value) ;

what I try is htmlspecialchars(‘<div class=“pinProcess”>’ . $value . “</div>”); }?>

and I get this output…
<div class=“pinProcess”>value</div> display on the screen…

help me out on how I can do it better…I want to safely output the $value and I want it inside <div class=“pinProcess”> value </div>

That pretty much dictates how the code should look, doesn’t it? :slight_smile:


echo '<div class="pinProcess">', htmlspecialchars($value), "</div>";

[QUOTE


echo '<div class="pinProcess">', htmlspecialchars($value), "</div>";

[/QUOTE]

thanks @ScallioXTX…it work fine.