FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


PHP Game..





Diablosblizz
Hey, I was wondering whats wrong with this code, i've tried a lot and I come up with nothing.

CODE:

Code:
<?php
$rand = (rand('0, 20'));
$post = $_POST['number'];

if ($rand == $post) {

echo "Congrats, the number was <b>$rand</b>!";
} else {

echo "Sorry, you guessed the wrong number! Try again. Remember the numbers are between 1-20!";
}
echo '$rand';
?>

<form action="randomnumber.php" method="post">
Your number: <input type="text" name="number">
<input type="submit" value="Submit!">
</form>


ERROR:
Code:
Warning: rand() expects exactly 2 parameters, 1 given in /home/diablos/domains/gamerzheaven.frih.net/public_html/hotelmario/games/randomnumber.php on line 2


Anybody have any ideas?[/code]
hexkid
Quote:
$rand = (rand('0, 20'));

The rand() function is called with one parameter: the 4-character string "0, 20".

I think you want
Code:
$rand = rand(0, 20);
manum
ya thats it rand(int,int) quotes shouldn't b there i guess
Diablosblizz
I was wondering if there was a way to see if the number is above 20, and if it is to show a error.. I tried this:
Code:

if ($post == 21+) {
echo "Its between 1 and 20... Try again";
}
...


I get a error when I do that.. So.. any ideas?
hexkid
http://www.php.net/manual/en/language.control-structures.php

and

http://www.php.net/manual/en/language.expressions.php
Maxus
Diablosblizz wrote:
I was wondering if there was a way to see if the number is above 20, and if it is to show a error.. I tried this:
Code:

if ($post == 21+) {
echo "Its between 1 and 20... Try again";
}
...


I get a error when I do that.. So.. any ideas?


that's easy stuff, learn it first Very Happy

never heard of >= ?
roboguyspacedude
if ($post > 20) {
echo "Its between 1 and 20... Try again";
}

the > makes it check only if it is greater than 20. You could also use
if ($post >= 21) {
echo "Its between 1 and 20... Try again";
}

It does the same thing.
X3 Talk
As per above. People say that PHP is really cryptic when debugging and it used to be my worst ememy. However when you get a feel for how PHP works, you'll find that being able to understand what UNEXPECTED T_IF IN JONES.PHP ON LINE 21 is really trying to tell you. Good luck with it.
Antoine_935
X3 Talk wrote:
you'll find that being able to understand what UNEXPECTED T_IF IN JONES.PHP ON LINE 21 is really trying to tell you. Good luck with it.

well, not hard... if there's something unexpected, that's because it shouldn't be there, or there is some error before...

PHP errors Strings are designed to be easy to understand.
Rhysige
Easy to understand once you understand what they say Razz Unexpected always mean that you havnt closed something above it which is somehow meaning you shouldnt be trying to use T_IF (if statement) usually you forgot ;
Related topics
Game Server For Frihost?_? Lol..
Ever made one?
hi !
[php]putting script fragments together?
My online php game
[JS] onclick to print out info
Does anyone know a really cool php game?
Inutile mais rigoureusement indispensable :)
the best car game ever???
Great games to play
Creating a page with php
Online game, anyone?
PHP Gaming?
Logging in a php game
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.