Browser MMO Video #5

Location of the Videos
User avatar
hallsofvallhalla
Site Admin
Posts: 12023
Joined: Wed Apr 22, 2009 11:29 pm

Re: Video#5

Post by hallsofvallhalla »

change it up how you want, just use it as a base to get started then modify it to make it work for you. No harm in that. Especially if it speeds up development.
Klone
Posts: 3
Joined: Tue May 10, 2011 12:44 am

Re: Video#5

Post by Klone »

hallsofvallhalla wrote:strange, post your code here, though if I was you I would keep watching the videos as it may fix itself on its own.
Here are my login codes:

authenticate.php:

Code: Select all

<?php
include_once "connect.php";
session_start();

if (isset($_POST['submit']))
{
	$player=$_POST['player'];
	$password=$_POST['password'];
	$player=strip_tags($player);
	$password=strip_tags($password);
	$password=md5($password);
	
	$query = "select name,password from players where name='$player' and password='$password'";
	$result = mysql_query($query) or die("Could not query players");
	$result2 = mysql_fetch_array($result);
	if ($result2)
	{
		$_SESSION['player']=$player;
		
		echo "<big>Logged in successfully<br />";
		echo "<a href='battle.php'>Continue</a></big>";
	}
	else
	{
		echo "<big>Wrong username or password. <a href='login.php'>Try Again</a></big>
	}
}
?>
login.php:

Code: Select all

<form method="POST" action="authenticate.php">
User Name: <input type="text" name="player" size="21" />
Password: <input type="password" name="password" size="21" mask="x" />
<br />
<input type="submit" value="Login" name="submit" />
The problem is that when I click Login, nothing appears on the authenticate.php page.
Klone
Posts: 3
Joined: Tue May 10, 2011 12:44 am

Re: Video#5

Post by Klone »

Klone wrote:
hallsofvallhalla wrote:strange, post your code here, though if I was you I would keep watching the videos as it may fix itself on its own.
Here are my login codes:

authenticate.php:

Code: Select all

<?php
include_once "connect.php";
session_start();

if (isset($_POST['submit']))
{
	$player=$_POST['player'];
	$password=$_POST['password'];
	$player=strip_tags($player);
	$password=strip_tags($password);
	$password=md5($password);
	
	$query = "select name,password from players where name='$player' and password='$password'";
	$result = mysql_query($query) or die("Could not query players");
	$result2 = mysql_fetch_array($result);
	if ($result2)
	{
		$_SESSION['player']=$player;
		
		echo "<big>Logged in successfully<br />";
		echo "<a href='battle.php'>Continue</a></big>";
	}
	else
	{
		echo "<big>Wrong username or password. <a href='login.php'>Try Again</a></big>
	}
}
?>
login.php:

Code: Select all

<form method="POST" action="authenticate.php">
User Name: <input type="text" name="player" size="21" />
Password: <input type="password" name="password" size="21" mask="x" />
<br />
<input type="submit" value="Login" name="submit" />
The problem is that when I click Login, nothing appears on the authenticate.php page.
Problem Solved. Missed the last quotation.
joedraco
Posts: 9
Joined: Wed Oct 05, 2011 9:05 pm

Re: Video#5

Post by joedraco »

Where did i go wrong?

I did on autenticate.php the following:

Code: Select all

<?php
include_once 'connect.php';
session_start();

if (isset($_POST['submit']))
(
  $player=$_POST['player'];
  $password=$_POST['password'];
  $player=strip_tags($player);
  $password=strip_tags($password);
  $password=md5($password);

  $query = "select name,password from players where name='$player' and '$password'";
  $result = mysql_query($query) or die("Could not query players");
  $result2 = mysql_fetch_array($result);
  if ($result2)
  (
     $_SESSION['player']=$player;

     echo "<big>Logged in successfully<br>";
     echo "<A href='battle.php'>Continue</a></big>";
  )
  else
  (
    echo "<big>Wrong username or password,<a href='login.php'>Try Again</a></big>";
  )
)
?>
and it written me : Parse error: syntax error, unexpected ';' in C:\wamp\www\tutorial\authenticate.php on line 7

please help.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Video#5

Post by Jackolantern »

You are not using the correct braces for your IF statements (something a lot of people do because it is hard to see in the videos):

This...

Code: Select all

if (isset($_POST['submit']))
(
  $player=$_POST['player'];
  $password=$_POST['password'];
  $player=strip_tags($player);
  $password=strip_tags($password);
  $password=md5($password);

  $query = "select name,password from players where name='$player' and '$password'";
  $result = mysql_query($query) or die("Could not query players");
  $result2 = mysql_fetch_array($result);
  if ($result2)
  (
     $_SESSION['player']=$player;

     echo "<big>Logged in successfully<br>";
     echo "<A href='battle.php'>Continue</a></big>";
  )
  else
  (
    echo "<big>Wrong username or password,<a href='login.php'>Try Again</a></big>";
  )
)
...needs to be like this:

Code: Select all

if (isset($_POST['submit']))
{     //changed ( to {, and made similar changes all the way down through the code
  $player=$_POST['player'];
  $password=$_POST['password'];
  $player=strip_tags($player);
  $password=strip_tags($password);
  $password=md5($password);

  $query = "select name,password from players where name='$player' and '$password'";
  $result = mysql_query($query) or die("Could not query players");
  $result2 = mysql_fetch_array($result);
  if ($result2)
  {
     $_SESSION['player']=$player;

     echo "<big>Logged in successfully<br>";
     echo "<A href='battle.php'>Continue</a></big>";
  }
  else
  {
    echo "<big>Wrong username or password,<a href='login.php'>Try Again</a></big>";
  }
}
See how you actually do use ( ) on a function call such as mysql_fetch_array(), but then to create the block of code for branching structures (like IF statements), you actually need to use { } braces. So you use ( ) for IF statement conditions, like in the very first line of the IF statement in the code quoted above, but then once you get into the actual code to be executed based on those conditions, you put it in { } braces.
The indelible lord of tl;dr
User avatar
Callan S.
Posts: 2042
Joined: Sun Jan 24, 2010 5:43 am

Re: Video#5

Post by Callan S. »

The curse of the curly brackets strikes again!!!1!
countvoldermort
Posts: 165
Joined: Tue Oct 13, 2009 4:22 pm

Re: Video#5

Post by countvoldermort »

I got ti the bit in the video where you checked and tryed to log on but i just get: Could not query player.

I cant see anything wrong with my codes, here they are
This is the login.php

Code: Select all

<form method="POST" action="authenticate.php">
User Name <input type="text" name="player" size="21">
Password <input type="password" name="password" size="21" mask="x">
<br>
<input type="submit" value="Login" name="submit">
This is the authenticate.php

Code: Select all

<?php
include_once 'connect.php';
session_start();

if (isset($_POST['submit']))
{
  $player=$_POST['player'];
  $password=$_POST['password'];
  $player=strip_tags($player);
  $password=strip_tags($password);
  $password=md5($password);

  $query = "select name,password from players where='$player' and '$password'";
  $result = mysql_query($query) or die("Could not query players");
  $result2 = mysql_fetch_array($result);
  if ($result2)
  {
    $_SESSION['player']=$player;

    echo "<big>Loggon in Successfully<br/>";
    echo "<a href='battle.php'>Continue</a></big>";
  }
  else
  {
    echo "<big>Wrong Username or Password.<a href='login.php'>Try Agin</a></big>";
  }
}
?>
Please check it, if you need any of the he oher scripts tell me
Im dumb;)
joedraco
Posts: 9
Joined: Wed Oct 05, 2011 9:05 pm

Re: Video#5

Post by joedraco »

after fixing this oriblem, and

THANK YOU VERY MUCH FOR IT

now it tells me:


( ! ) Notice: Undefined index: player in C:\wamp\www\tutorial\authenticate.php on line 7
Call Stack
# Time Memory Function Location
1 0.0028 372560 {main}( ) ..\authenticate.php:0
Wrong username or password,Try Again

what the hell is wrong?


Here is the code again if i missed something:

Code: Select all

<?php
include_once 'connect.php';
session_start();

if (isset($_POST['submit']))
{
  $player=$_POST['player'];
  $password=$_POST['password'];
  $player=strip_tags($player);
  $password=strip_tags($password);
  $password=md5($password);

  $query = "select name,password from players where name='$player' and '$password'";
  $result = mysql_query($query) or die("Could not query players");
  $result2 = mysql_fetch_array($result);
  if ($result2)
  {
     $_SESSION['player']=$player;

     echo "<big>Logged in successfully<br>";
     echo "<A href='battle.php'>Continue</a></big>";
  }
  else
  {
    echo "<big>Wrong username or password,<a href='login.php'>Try Again</a></big>";
  }
}
?>
Valhala said i need no skills in this program and he will teach the viewer all along the way, but with these errors I start to doubt that.
User avatar
hallsofvallhalla
Site Admin
Posts: 12023
Joined: Wed Apr 22, 2009 11:29 pm

Re: Video#5

Post by hallsofvallhalla »

Once again I would watch until video 14 or so before doing the code

this must be fixed as well

Code: Select all

$query = "select name,password from players where name='$player' and '$password'";
to

Code: Select all

$query = "select name,password from players where name='$player' and password ='$password'";
make sure you ended your form with </form>
User avatar
OldRod
Posts: 1320
Joined: Sun Sep 20, 2009 4:26 pm

Re: Video#5

Post by OldRod »

joedraco wrote:Valhala said i need no skills in this program and he will teach the viewer all along the way, but with these errors I start to doubt that.
That's true for the most part - the videos show you everything you need to do. However... if something goes wrong, you need to be able to figure out what happened and how to fix it. So there is some skill needed, but really very little.

It's more about developing the mind set of a programmer.

When you enter code that you saw in the video and it crashes, but it worked in the tutorial, then you have to double check that you entered everything correctly. The code you are doing works in the video, therefore it is good code. If something is not working for you, it's most likely a setup issue (something in your database is not set up the same as Halls') or a typo in your code.

Hang in there, you'll get it. And the more you find and fix these little annoying errors, the more likely you'll be able to spot them in the future :)
Post Reply

Return to “Older Browser MMO Videos”