PHP我的数学不起作用,我的VARABLE显示为0,但它是另一回事
所以我的问题是,我在脚本的开头设置了变量,在脚本的后面,我需要这个变量来做一些数学运算,以便它知道它是否有钱买东西,以及它是否没有钱买东西。这是我的剧本 错误会一直显示在脚本的底部PHP我的数学不起作用,我的VARABLE显示为0,但它是另一回事,php,sql,math,Php,Sql,Math,所以我的问题是,我在脚本的开头设置了变量,在脚本的后面,我需要这个变量来做一些数学运算,以便它知道它是否有钱买东西,以及它是否没有钱买东西。这是我的剧本 错误会一直显示在脚本的底部 $user = 'Ramon'; // get integer data from url $removeslash = "/xampp/"; $actual_link3 = "$_SERVER[REQUEST_URI]"; $actual_link2 = str_replace($removeslash,
$user = 'Ramon';
// get integer data from url
$removeslash = "/xampp/";
$actual_link3 = "$_SERVER[REQUEST_URI]";
$actual_link2 = str_replace($removeslash,"",$actual_link3);
$actual_link = str_replace(".php","",$actual_link2);
echo $actual_link;
// connect to mysql database
$conn = mysqli_connect($host,$username,$password, $database);
if (!$conn) {
die('Not connected : ' . mysqli_error());
}
$result = mysqli_query($conn, "SELECT * FROM Bedrijf WHERE ID='".$actual_link."'");
$row = mysqli_fetch_array($result);
$NaamBedrijf = $row['Name'];
$WorthNow = $row['WorthNow'];
$result2 = mysqli_query($conn, "SELECT * FROM Users WHERE Username='".$user."'");
$row2 = mysqli_fetch_array($result2);
$Aandelen = $row2['Shares'.$actual_link];
$Money = $row2['Money'];
echo "IK HRB NU".$Aandelen;
//Waarde aandelen berkenen
$WaardePort = $Aandelen * $WorthNow;
//Geld formateren van 1293384 naar $1,293,384.00
setlocale(LC_MONETARY, 'en_US');
$MoneyFOR = money_format('%(#10n', $Money) . "\n";
$WaardePort = money_format('%(#10n', $WaardePort) . "\n";
$WaardeNU = money_format('%(#10n', $WorthNow) . "\n";
echo "AANDELEN:".$Aandelen;
echo "<html>
<head>
<title>Beurs</title>
<link rel='stylesheet' type='text/css' href='index.css'/>
</head>
<body>
<center>
<table>
<tr>
<td width='992px'>
<p class='ingelogd'>Je bent ingelogd Als ".$user."</p>
</td>
</tr>
<tr>
<td width='992px'>
<p>Er staat ".$MoneyFOR." Dollar op je bank.</p>
</td>
</tr>
</table><br/>
<table>
<tr>
<td id='Title' width='992px'>Je Kunt Informatie zien over je aandelen en aandelen verkopen/kopen.</td>
</tr>
</table>
<table width='1000px'>
<tr>
<td>".$NaamBedrijf."</td>
<td>".$WaardeNu."</td>
<td>".$Aandelen."</td>
</tr>
<tr>
<form>
<td>Kopen of Verkopen?</td>
<td>
<input type='radio' name='1' value='1'>Verkopen</input>
<input type='radio' name='2' value='2'>Kopen</input><br/>
</td>
<td>Aantal andelen:<input style='width:85px;' type='text' name='Totaal'/><input type='submit' name='submit' value='Koop/Verkoop'/></td>
</form>
</tr>
</table>
<table>
<tr>
<td width='992px'><label>Je aandelen zijn ".$WaardePort." Dollar Waard.</label><input type='submit' name='back' value='Ga Terug naar overzicht'/></td>
</tr>
</table>
</center>
</body>
</html>";
echo "AANDELEN:".$Aandelen;
if($_GET){
if(isset($_GET['submit'])){
if(isset($_GET['1'])){
echo "Aandelen totaal:".$_GET['Totaal'];
echo "Hoeveel aandelen heb ik: ".$Aandelen;
if (!$_GET['Totaal'] > $Aandelen) { //ERROR IS HERE AND BELOW
echo "<center><p style='color:red; font-weight:bold;'>je hebt niet zoveel andelen!</p></center>";
}else{
$jekrijgt = $WorthNow * $_GET['Totaal'];
$Aandelen = $Aandelen - $_GET['Totaal'];
$Money = $jekrijgt + $Money;
echo "Je hebt ".$_GET['Totaal']." Aandelen Verkocht Voor: ".$Money;
echo $Aandelen;
}
}else{
echo "BUY";
}
}
}
?>
解释
当在If语句之前回显变量aandelen时,它会显示得非常好,但是当我尝试做一些数学运算时,当它没有那么多的份额saandelen时,它会回显你没有那么多的份额。但是,即使你没有那么多的股份,你也会卖出股票
要查看出了什么问题,请检查$_GET['total']在>运算符之前处理
这意味着只有当total为真时,它才会在数字上为零,或者如果total为空或为零,它才会为一
否定>的正确方法是使用此选项没有真正的帮助,因为我已经有了这样的选项,但也不起作用。它总是说我卖了股票,但当我填写一个比我有更多的数字时,它仍然说你卖了。。。。安德伦
if( $_GET['Totaal'] <= $Aandelen)