Page 1 of 1

Authenticate.php

Posted: Sat Feb 18, 2012 4:11 pm
by Zorber
Hey guys, I used the search for an answer, but didn't find anything helpful.
I was trying to copy Hall's code from video 5 because he didn't post the source, and it was a bit blurry and I ended up getting a lot of errors.

Errors;
Parse error: syntax error, unexpected T_VARIABLE in C:\wamp\www\tutorial\authenticate.php on line 8
Parse error: syntax error, unexpected ';' in C:\wamp\www\tutorial\authenticate.php on line 7


My 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'";
  $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>";
   )
)
?>
Thanks, if there is anything else you need let me know.

Sincerely,
Zorber.

Re: Authenticate.php

Posted: Sat Feb 18, 2012 4:32 pm
by Zorber
I copied and pasted your code in and got this

Fatal error: Can't use function return value in write context in C:\wamp\www\tutorial\authenticate.php on line 18

Re: Authenticate.php

Posted: Sat Feb 18, 2012 5:26 pm
by Zorber
Close, but no cigar.

Re: Authenticate.php

Posted: Sat Feb 18, 2012 6:03 pm
by Chris
Were a lot of small errors. Compare your script with this:

Code: Select all

include_once 'connect.php';
session_start();

if (isset($_POST['submit']))
{
    $player   = mysql_real_escape_string($_POST['player']);
    $password = md5($_POST['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 '<h1>Logged in successfully</h1>';
        echo '<a href="battle.php">Continue</a><';
    }
    else
    {
        echo '<h1>Wrong username or passwordcombination.</h1>';
        echo '<a href="login.php">Try Again</a>';
    }
} 

Re: Authenticate.php

Posted: Sat Feb 18, 2012 7:51 pm
by Zorber
Thanks a lot Chris :)