What's wrong with my Script?
Posted: Mon Sep 29, 2003 10:11 am
Hello all,
I have an upcoming contest coming up for the small electrical appliance industry, anyhow, here is my problem.
Users come online, they enter their form information, once they click on submit, the first thing that happens is that the script gets a numeric value from a table having only one row. It takes that value and assigns it as the user's contestandID.
Once it has that contestandID, before it leaves the table, it increments that value in that table by 1 to accomodate the next user to come in. For some reason, this is not working.
If the user bought say a GE product already, then the info goes into the db.
Anyhow, the user gets instant notification whether he is a winner or not.
For instance, say every 49th user gets a prizeA and the next 49th entrant gets prizeB, and which prize he gets, gets recorded into the db.
My script isn't running, I would apreciate any help anyone can provide, here is the relevant code, thanks.
<?php
$age = $HTTP_POST_VARS['age'];
// all http post vars go here for all form variables.
require("dbConnectionStrings.php");
$sql = "SELECT contestantID FROM tableName1";
$result = mysql_query($sql) or die(mysql_error());
$userID = $contestantID++;
$sql2 = "UPDATE tableName1 SET contestantID = '$userID'";
$result2 = mysql_query($sql2) or die(mysql_error());
?>
UserID is: <?php echo "$userID"; ?> // for some reason, userID is always NULL
<?php
function noPrize()
{
$today = date("F j, Y, g:i a");
$sql3 = "INSERT INTO tableName2(contestantID, age, fname, lname, address, city, province, pnumber,contest, Postal, date, type, email, isWinner, prize, purchase)
VALUES ('$contestantID', '$age', '$fname', '$lname', '$address', '$city', '$prov', '$pnumber','$cnt','$postal', '$today', '$type', '$email', 0, 0, 0)";
$result3 = mysql_query($sql3) or die(mysql_error());
}
function prizeA()
{
$sql4 = "INSERT INTO tableName2(contestantID, age,fname,lname,address,city,province, pnumber, Postal, date, type, email, isWinner, prize, purchase
VALUES ('$contestantID', '$age', '$fname', '$lname', '$address', '$city', '$prov', '$pnumber','$cnt','$postal', '$today', '$type', '$email', 1, 1, 0)";
$result4 = mysql_query($sql4) or die(mysql_error());
}
function prizeB()
{
$sql5 = "INSERT INTO tableName2(contestantID, age,fname,lname,address,city,province, pnumber, contest, Postal, date, type, email, isWinner, prize, purchase)
VALUES ('$contestantID', '$age', '$fname', '$lname', '$address', '$city', '$prov', '$pnumber','$cnt','$postal', '$today', '$type', '$email', 1, 2, 0)";
$result5 = mysql_query($sql5) or die(mysql_error());
}
?>
<?php
$sql6="select contestantID, count(contestantID) as winners
from tableName2
where isWinner=1
group by contestantID";
$result6 = mysql_query($sql6) or die(mysql_error());
?>
ContestandID is:<?php echo "$contestantID"; ?><br>UserID is:<?php echo "$userID"; ?><br> Winners:<?php echo "$winners"; ?><br>//both userID and winners are always NULL, don't know why
<?php
if ($winners < 25)
{
if (($contestantID -10) % 98 == 0)
{ prizeB(); }
elseif (($contestantID -10) % 49 == 0)
{ prizeA(); }
else { noPrize(); }
}
else { noPrize(); }
?>
I would apreciate any help anyone can provide, this is driving me nuts, I couldn't figure it out for a days. When submit is clicked, the entrantID in tableName1 doesn't get incremented, and in tableName2, everything is equal to 0 and some values are NULL.
Some plz help.
thanks
I have an upcoming contest coming up for the small electrical appliance industry, anyhow, here is my problem.
Users come online, they enter their form information, once they click on submit, the first thing that happens is that the script gets a numeric value from a table having only one row. It takes that value and assigns it as the user's contestandID.
Once it has that contestandID, before it leaves the table, it increments that value in that table by 1 to accomodate the next user to come in. For some reason, this is not working.
If the user bought say a GE product already, then the info goes into the db.
Anyhow, the user gets instant notification whether he is a winner or not.
For instance, say every 49th user gets a prizeA and the next 49th entrant gets prizeB, and which prize he gets, gets recorded into the db.
My script isn't running, I would apreciate any help anyone can provide, here is the relevant code, thanks.
<?php
$age = $HTTP_POST_VARS['age'];
// all http post vars go here for all form variables.
require("dbConnectionStrings.php");
$sql = "SELECT contestantID FROM tableName1";
$result = mysql_query($sql) or die(mysql_error());
$userID = $contestantID++;
$sql2 = "UPDATE tableName1 SET contestantID = '$userID'";
$result2 = mysql_query($sql2) or die(mysql_error());
?>
UserID is: <?php echo "$userID"; ?> // for some reason, userID is always NULL
<?php
function noPrize()
{
$today = date("F j, Y, g:i a");
$sql3 = "INSERT INTO tableName2(contestantID, age, fname, lname, address, city, province, pnumber,contest, Postal, date, type, email, isWinner, prize, purchase)
VALUES ('$contestantID', '$age', '$fname', '$lname', '$address', '$city', '$prov', '$pnumber','$cnt','$postal', '$today', '$type', '$email', 0, 0, 0)";
$result3 = mysql_query($sql3) or die(mysql_error());
}
function prizeA()
{
$sql4 = "INSERT INTO tableName2(contestantID, age,fname,lname,address,city,province, pnumber, Postal, date, type, email, isWinner, prize, purchase
VALUES ('$contestantID', '$age', '$fname', '$lname', '$address', '$city', '$prov', '$pnumber','$cnt','$postal', '$today', '$type', '$email', 1, 1, 0)";
$result4 = mysql_query($sql4) or die(mysql_error());
}
function prizeB()
{
$sql5 = "INSERT INTO tableName2(contestantID, age,fname,lname,address,city,province, pnumber, contest, Postal, date, type, email, isWinner, prize, purchase)
VALUES ('$contestantID', '$age', '$fname', '$lname', '$address', '$city', '$prov', '$pnumber','$cnt','$postal', '$today', '$type', '$email', 1, 2, 0)";
$result5 = mysql_query($sql5) or die(mysql_error());
}
?>
<?php
$sql6="select contestantID, count(contestantID) as winners
from tableName2
where isWinner=1
group by contestantID";
$result6 = mysql_query($sql6) or die(mysql_error());
?>
ContestandID is:<?php echo "$contestantID"; ?><br>UserID is:<?php echo "$userID"; ?><br> Winners:<?php echo "$winners"; ?><br>//both userID and winners are always NULL, don't know why
<?php
if ($winners < 25)
{
if (($contestantID -10) % 98 == 0)
{ prizeB(); }
elseif (($contestantID -10) % 49 == 0)
{ prizeA(); }
else { noPrize(); }
}
else { noPrize(); }
?>
I would apreciate any help anyone can provide, this is driving me nuts, I couldn't figure it out for a days. When submit is clicked, the entrantID in tableName1 doesn't get incremented, and in tableName2, everything is equal to 0 and some values are NULL.
Some plz help.
thanks