Hello there! first of all let me say: THANK YOU to indie-resource... for existing and to hallsofValhalla for guiding me here
I am at his "3b" video in making a browser MMORPG, and I get tons of errors when trying to press the Submit button...
Error: Fatal error: Function name must be a string in D:\Programfiler (x86)\wamp\www\tutorial\reguser.php on line 6
Code:
<?php
include 'connect.php';
?>
<?php
$players=$_POST('player');
$password=$_POST('password');
$repassword=$_POST('repassword');
$player=strip_tags($player);
$email=$_POST('email');
$email=strip_tags($email);
if ($email == "")
{
echo "Please enter a email address!<br>";
echo " <A href='register.php'>Go back</a>";
exit;
}
if ($password==$repassword)
{
$isplayer="SELECT * from players where name='$player'";
$isplayer2=mysql_query($isplayer) or die("Could not query players table");
$isplayer3=mysql_fetch_array($isplayer2);
if(!$_POST('password') || !$_POST('repassword'))
{
print "Please enter a password<br>";
echo " <A h ref='register.php'>Go back</a>";
exit;
}
else if($isplayer3)
{
print "That username is already in use! Please choose another one.";
echo " <A href='register.php'>Go back</a><br>";
exit;
}
else if(strlen($player)>20 || strlen($player)<3)
{
print "Your username is either too long or too short. It needs to be between 3-20 letters.";
echo " <A href='register.php'>Go back</a><br>";
exit;
}
else
{
$isemail="SELECT * from players where email='$email'";
$isemail2=mysql_query($isemail) or die("Not able to query for email");
$isemail3=mysql_fetch_array($isemail2);
if($isemail3)
{
print "That E-mail address is already in use!";
echo "A href='register.php'>Go back</a><br>";
exit;
}
else
{
$password=md5($password);
$SQL ="INSERT into players(name, password, email, level, xp) VALUES ('$player','$password','1','1')";
mysql_query($SQL) or die("Could not register");
print "Thank you for registering!";
}
}
}
else
{
print "Your password didn't match or you did not enter a password";
echo " <A href='registter.php'>Go back></a><br>";
exit;
}
echo " <A href='login.php'>Click here to log in!</a><br>";
?>
randomalexlol wrote:There are a few errors you have done, such as putting $_POST('player') instead of $_POST['player'] easy mistake.
Here's how i would code it
i use $_REQUEST because it can pick up both $_POST and $_GET so it's good but also bad if you like to have different values sent in the same name to the same place.
i try not to use else{} as much as possible it just makes things way too complicated as soon as you have more than one else, so i just do "if this is wrong, kill everything otherwise continue as normal".
even though the "die;" is within a if(){} it will kill the entire script.
<?php
include("connect.php");
if(!$_REQUEST['player'] || $_REQUEST['player']==""){
//no player name given
die;
}
if(!$_REQUEST['password'] || $_REQUEST['password']==""){
//no password given
die;
}
if(!$_REQUEST['repassword'] || $_REQUEST['repassword']==""){
//no 2nd password given
die;
}
if(!$_REQUEST['email'] || $_REQUEST['email']==""){
//no email given
die;
}
$players = strip_tags($_REQUEST['player']);
$password = md5($_REQUEST['password']);
$password2 = md5($_REQUEST['repassword']);
$email = strip_tags($_REQUEST['email']);
if(strlen($players) > 20 || strlen($players) < 3){
//player name not between 3 and 20
die;
}
if(filter_var($email,FILTER_VALIDATE_EMAIL)==false){
//not a real email address error goes here
die;
}
if($password!==$password2){
//passwords do not match error goes here
die;
}
$search_for_player = mysql_query("select * from `players` where `name`='".$player."'");
$search_for_player_nr = mysql_num_rows($search_for_player);
if($search_for_player_nr!==0){
//that player name already exists
die;
}
$search_for_email = mysql_query("select * from `players` where `email`='".$email."'");
$search_for_email_nr = mysql_num_rows($search_for_email);
if($search_for_email_nr!==0){
//that email is already in use
die;
}
mysql_query("insert into `players` (`name`,`password`,`email`,`level`,`xp`) values ('".$player."','".$password."','".$email."','1','1')");
?>
Thank You For Registering :)
Thank you very much :p I had already fixed this (I'm stuck with another problem though ) There was tons of minor errors in this one...
But now I'm on video "5" and I'm making the attack.php ...
It worked fine until I killed the goblin... However, the "orc" won't loose hitpoints when I hit him...
Our typical advice is to not type anything until you get to at least video 14 or further. This is because you will have seen basic code structures enough by then to be able to spot the $_POST('player') vs. $_POST['player'] issues, and because the game is not in a playable state until much further along. You are going to get a ton of errors if you try to run it way before video 14 because too many systems are missing. You simply won't have a runable program.