Page 33 of 35

Re: Video#5

Posted: Sat Jun 25, 2011 8:04 pm
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.

Re: Video#5

Posted: Sat Jul 16, 2011 2:46 am
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.

Re: Video#5

Posted: Sat Jul 16, 2011 3:16 am
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.

Re: Video#5

Posted: Fri Oct 07, 2011 1:42 am
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.

Re: Video#5

Posted: Fri Oct 07, 2011 3:40 am
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.

Re: Video#5

Posted: Fri Oct 07, 2011 3:56 am
by Callan S.
The curse of the curly brackets strikes again!!!1!

Re: Video#5

Posted: Fri Oct 07, 2011 6:55 am
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

Re: Video#5

Posted: Fri Oct 07, 2011 8:35 am
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.

Re: Video#5

Posted: Fri Oct 07, 2011 1:41 pm
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>

Re: Video#5

Posted: Fri Oct 07, 2011 2:58 pm
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 :)