Forum Moderators: coopster
I tried to simplify my pages below - hope this makes sense!
Let's say I have a php page with a simple form:
<form name="example" method="post" action="register.php">
<input name="userid" type="hidden" id="userid" value="<? echo $userid;?>"><br>
address: <input name="address" type="text" id="address" maxlength="40" value="<? echo $address;?>"><br>
city: <input name="city" type="text" id="city" maxlength="40" value="<? echo $city;?>"><br>
state: <input name="state" type="text" id="state" maxlength="40" value="<? echo $state;?>"><br>
<input type=button value="Post My Information">
<br><br>
</form>
Let's say the register.php page looks something like this:
<HTML>
<HEAD>
</head>
<body>
<?
include 'db.php';
$userid = $_POST['userid'];
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$sql = mysql_query("INSERT INTO pages (userid, address, city, state)
VALUES('$userid', '$address', '$city', '$state')") or die (mysql_error());
if(!$sql){
echo '<font color=red>There has been an error. Please contact the webmaster.';
}
?>
</body></html>
Let's say I have another database called "users", where John is listed as a user. Now users has a field called "allowed". "allowed" are the number of times a particular user is allowed to submit the form above. John uses the form. I want John's information to be posted to the database "pages", and I also want John's value of "allowed" in the database "users" to decrease by 1. If John tries to use the form and "allowed" is equal to zero, I want John to get an error message and the form won't submit. What I am trying to do is set up a credit system.
I did a little research, and found out I need to use Decrement Operators after post ($allowed--). I'm not quite sure how all this works. Could someone please point me in the right direction?
Get a table where you have the fields of userid, and post_left or something similar.
Before the insert statement, check the value of the post_left, if it is more than zero, allow the insertion.
And right after the insertion, you can update the table with post_left = post_left - 1;
Hope this helps.
Habtom
Sorry it has taken me so long to respond. Just want to thank you so much for your help.
It took me quite some time to make this work (I had to learn a little about arrays, "serialize", getting other session variables to pass, etc.), but I think I got it...with your help. allowed=allowed-1 worked like a charm.
You always come through, and I really want to thank you!