Hey guys. I have another problem if some else if statements. I have a coding which should pass everything ok, and come say the end result Purchase complete, but instead it comes up with my other defined message 'This is not a number'. I beleive this is because of the ereg coding i am using, but am unsure to why it isnt working.
My code for this is:
<?php include "session.php";
include "Connect.php";
include "buildinginfo.php";
?>
<title>Building Transaction</title>
<?php
$userid=mysql_real_escape_string($userid);
$password=mysql_real_escape_string($password);
$userid=$_SESSION['userid'];
$password=$_SESSION['password'];
$_SESSION['userid']=$userid;
$_SESSION['password']=$password;
if($rec=mysql_fetch_array(mysql_query("SELECT * FROM $table WHERE userid='$userid' AND password = '$password'"))){
if(($rec['userid']==$userid)&&($rec['password']==$password)){
$_SESSION[userid]=$userid;
$_SESSION[password]=$password;
mysql_connect($servername,$dbusername,$dbpassword);
@mysql_select_db("$dbname");
$userstats="SELECT * FROM $table WHERE userid='$_SESSION[userid]'";
$userstats2=mysql_query($userstats);
$userstats3=mysql_fetch_array($userstats2);
$Sturdytentcost2=$Sturdytentcost*$SturdyTent;
if ($SturdyTent<0){ print "<CENTER><br><br>You cant build less than one building. Its just physically impossible<br><a href=buildings.php>click here to return</a></CENTER>";}
else if ($userstats3[gold]<$Sturdytentcost){print "<CENTER><br><br><br>Insufficient funds for this purchase ot you cannot order under 0 buildings<br><a href=buildings.php>click here to return</a></CENTER>";}
else if (ereg ("([0-9]{1,9})", $SturdyTent, $regs)){
$updatetotalpop2="UPDATE $table SET SturdyTent=SturdyTent+'$SturdyTent', gold=gold-$Sturdytentcost2,middleclasspop=middleclasspop+'$sturdytentpop'*'$SturdyTent',middleclassunemployent =middleclassunemployent +'$sturdytentpop'*'$SturdyTent' WHERE userid='$_SESSION[userid]'";
mysql_query($updatetotalpop2) or die("error with SturdyTent. Please report to Admin");
print "<CENTER><br><br><br>Purchase complete<br><a href=buildings.php>click here to return</a></CENTER>";
}else{
print "<CENTER><br><br><br>This is not a number<br><a href=buildings.php>click here to return</a></CENTER>";}
}}
?><style type="text/css">
<!--
body,td,th {
color: #990000;
}
body {
background-color: #000000;
}
-->
</style>
Like is said before, i think its because of the ereg statement but im really not too sure, Thanks for any help given