Authenticate.php

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
Zorber
Posts: 103
Joined: Wed Jun 15, 2011 2:51 am

Authenticate.php

Post 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.
Zorber
Posts: 103
Joined: Wed Jun 15, 2011 2:51 am

Re: Authenticate.php

Post 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
Zorber
Posts: 103
Joined: Wed Jun 15, 2011 2:51 am

Re: Authenticate.php

Post by Zorber »

Close, but no cigar.
User avatar
Chris
Posts: 1581
Joined: Wed Sep 30, 2009 7:22 pm

Re: Authenticate.php

Post 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>';
    }
} 
Fighting for peace is declaring war on war. If you want peace be peaceful.
Zorber
Posts: 103
Joined: Wed Jun 15, 2011 2:51 am

Re: Authenticate.php

Post by Zorber »

Thanks a lot Chris :)
Post Reply

Return to “Beginner Help and Support”