更新记录然后删除

I'm trying to update one record and then delete another in one go, however it's only allowing me to do one or the other;

$update = "UPDATE user SET felcredits = '$value' WHERE username = '$user'";
$update2 = "DELETE FROM playeritems WHERE id = '$realid'";

How do I get it to do both? I have tried the following;

$update = "UPDATE user SET felcredits = '$value' WHERE username = '$user'";
$update = "DELETE FROM playeritems WHERE id = '$realid'";

__

$update = "UPDATE user SET felcredits = '$value' WHERE username = '$user' DELETE FROM playeritems WHERE id = '$realid'";

__

FULL CODE:

if ($_SERVER['REQUEST_METHOD'] = $_POST AND isset($_POST['sell'])) {
$sql = "SELECT felcredits FROM user WHERE username = '$user'";
$result = $db_conn->query($sql);
if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        $felcredits = $row['felcredits'];
    }
}
$value = $felcredits + $value;
$update = "UPDATE user SET felcredits = '$value' WHERE username = '$user'";
$update2 = "DELETE FROM playeritems WHERE id = '$realid'";
if ($db_conn->query($update) === TRUE) {
    echo "<br />Details Updated";
} else {
    echo "Error: " . $insert . "<br>" . $db_conn->error;
}

}

You Try change in Your full code Like this

in your Execute code


if ($_SERVER['REQUEST_METHOD'] = $_POST AND isset($_POST['sell'])) {
 $sql = "SELECT felcredits FROM user WHERE username = '$user'";
$result = $db_conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
    $felcredits = $row['felcredits'];
}
}       
$value = $felcredits + $value;
$update = "UPDATE user SET felcredits = '$value' WHERE username = '$user'";
$update2 = "DELETE FROM playeritems WHERE id = '$realid'";
if (($db_conn->query($update) === TRUE) && ($db_conn->query($update2) ===     TRUE)) {
echo "<br />Details Updated";
} else {
echo "Error: " . $insert . "<br>" . $db_conn->error;
}
}

The problem is here:

$update = "UPDATE user SET felcredits = '$value' WHERE username = '$user'";
$update = "DELETE FROM playeritems WHERE id = '$realid'";

your second sql query will override the first one, so make separate query like:

$update = "UPDATE user SET felcredits = '$value' WHERE username = '$user'";
mysqli_query($conn, $update);

$delete = "DELETE FROM playeritems WHERE id = '$realid'";
mysqli_query($conn, $delete);

where $conn is the connection handle