oh i think my english is confusing, the code works, except for the already exist one,n that one doesnt work
and the ony select i see is for the already exist, update is for the same table, it has several columns.
You could set the auction_id column to be a unique field, run the insert, and you’ll get an error if the table already has a row with that value in it. If you don’t get an error, then it must have inserted the new row.
But your code doesn’t actually work that way - you do the SELECT after you’ve inserted the row, so unless the insert fails, you’re always going to get a result. Surely if you only want one row for each auction_id value, you should do the select first, and then only do the insert if you get no results?
All this relies on you checking for errors after you’ve run the queries. Your code doesn’t seem to do that, unless the framework is doing it for you.
I’m confused - you do the SELECT at the end, after you’ve done the insert and the update. If you want to do the select first to see if it’s already present, surely you have to do that before the insert?
yeah u right, stuff got me all confuse at first but then it seem to submit the form even if its has checked and see that it already exist below is the layout again i believe am suppose to use if and else to make that happen
if (isset($_POST['action']) && $_POST['action'] == 'update')
{
//update balance
$query = "UPDATE " . $DBPrefix . "users u SET u.balance = :balance + balance WHERE u.id IN (SELECT b.bidder FROM " . $DBPrefix . "bids b
WHERE b.auction = :auction)";
$params = array();
$params[] = array(':balance', $system->input_money($_POST['balance']), 'float');
$params[] = array(':auction', $id, 'int');
$db->query($query, $params);
if (isset($_POST['action']) && $_POST['action'] == 'update')
{
$query = "SELECT all_clicked FROM " . $DBPrefix . "buttonclicked WHERE all_clicked = '1' AND auction_id = :auction";
$params = array();
$params[] = array(':auction', $id, 'int');
$db->query($query, $params);
if ($db->numrows() > 0)
{
$errmsg = $ERR_0099;
}
else{
//insert button click
$query = "INSERT INTO " . $DBPrefix . "buttonclicked (auction_id, all_clicked) VALUES(:auction_id, :all_clicked);";
$params = array();
$params[] = array(':auction_id', $id, 'int');
$params[] = array(':all_clicked', $_POST['all_clicked'], 'str');
$db->query($query, $params);
header('location: listusers.php?PAGE=' . intval($_POST['offset']));
exit;
}
}}
still not working well still submit and then shows the error msgs