vendredi 9 janvier 2015

Higher / lower game


Vote count:

0




I'm trying to make a higher / lower number game. So basically you get one number and the start and then you click a button - higher or lower. So if you click higher and the next number is higher you win otherwise you lose , same goes for lower.The problem comes when I click some of the buttons it gives a new number. So how can I prevent this? Here's my code:



<!DOCTYPE html>
<html>
<head>
<title> Gamble </title>
<meta charset="utf-8">
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<?php

include('config.php');
if(!$_SESSION['username']) {
header("Location: index.php");
}

Menu();
isOnline();

$number = rand(0, 100);
echo $number;


if(isset($_POST['higher']) || isset($_POST['lower'])) {
$num = $number;
$newNumber = rand(0, 100);
if($_POST['higher']) {
if($newNumber > $num) {
echo 'You win!<br>'.$newNumber;
}
}
}

?>
<form method="POST">
<input type="Submit" name="higher" value="Higher">
<input type="Submit" name="lower" value="Lower">
</form>
</body>
</html>


*Note: I know the lower button does not work , I just want to make it for higher 'cause it will work on the same way with lower..



asked 6 mins ago







Higher / lower game

Aucun commentaire:

Enregistrer un commentaire