1

Topic: Balance

How to make, that at zero balance produced an error and the data in the table did not register?
There are two tables one usertbl (id, username, password, balance) articles (id, gnumber, telephone, author, publicationdate)

session_start ();
if (! isset ($ _SESSION ["session_username"])):
header ("location:login.php");
else:
?>
<? php
if (isset ($ _POST ["add"])) {
$gnumber = htmlspecialchars ($ _POST [' gnumber ']);
$telephone=htmlspecialchars ($ _POST [' telephone ']);
$author=htmlspecialchars ($ _POST [' author ']);
$publicationdate=htmlspecialchars ($ _POST [' publicationdate ']);
if (! empty ($gnumber) &&! empty ($telephone) &&! empty ($author) &&! empty ($publicationdate)) {
$sql = "INSERT INTO articles (gnumber, telephone, author, publicationdate) VALUES (' $gnumber ', ' $telephone ', ' $author ', ' $publicationdate ')";
$result=mysqli_query ($con, $sql);
$editbalance = "UPDATE usertbl SET balance=balance-1 WHERE username = '". $ _ SESSION [' session_username ']. "'";
$minus=mysqli_query ($con, $editbalance);
header ("Cache-Control: no-store, no-cache, mustrevalidate");
} else {
$message = "the User name is already occupied!";
}
} else {
$message = "All fields are mandatory for filling!";
}
?>
<? php
$balance = mysqli_query ($con, "SELECT * FROM usertbl WHERE username = '". $ _ SESSION [' session_username ']. "'");
while ($myrow = mysqli_fetch_assoc ($balance))
{echo ' <b> Balance: '. $myrow [' balance ']. ' </b> ';}?>

2

Re: Balance

You were mistaken a forum. To you in section on PHP.

3

Re: Balance

To add request about check of balance and by result of check to fulfill necessary actions. Not a variant?