login code not working!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
synchro
Forum Newbie
Posts: 4
Joined: Thu Feb 07, 2008 2:18 pm

login code not working!

Post by synchro »

hey guys
i have a login.php and login.html
the login isnt working
i get the following error:

parse error: syntax error, unexpected T_STRING in C:\wamp\www\login.php on line 19
here is the login.php code, that apparently wrong!:

Code: Select all

<?php
 
//Database Information
 
$dbhost = "localhost";
$dbname = "mydatabase";
$dbuser = "root";
$dbpass = "clio172";
 
//Connect to database
 
mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());
 
session_start();
$username = $_POST[‘username’];
$password = md5($_POST[‘password’]);
 
$query = “Select * from mytable where username=’$username’ and password=’$password’”;
 
$result = mysql_query($query);
 
if (mysql_num_rows($result) != 1) {
$error = “Bad Login”;
    include “login.html”;
 
} else {
    $_SESSION[‘username’] = “$username”;
include “registration.html”;
   
}
 
?>
and the login.html file:

Code: Select all

<form name="login" method="post" action="login.php">
<table border="0" width="225" align="center">
    <tr>
        <td width="219" bgcolor="#999999">
            <p align="center"><font color="white"><span style="font-size:12pt;"><b>Login</b></span></font></p>
        </td>
    </tr>
    <tr>
        <td width="219">
            <table border="0" width="220" align="center">
                <tr>
                    <td width="71"><span style="font-size:10pt;">Username:</span></td>
                    <td width="139"><input type="text" name="username"></td>
                </tr>
                <tr>
                    <td width="71"><span style="font-size:10pt;">Password:</span></td>
                    <td width="139"><input type="password" name="password"></td>
                </tr>
                <tr>
                    <td width="71">&nbsp;</td>
                        <td width="139">
                            <p align="right"><input type="submit" name="submit" value="Submit"></p>
                        </td>
                </tr>
            </table>
        </td>
    </tr>
    <tr>
        <td width="219" bgcolor="#999999"><font color="white">Not Registered? </font>
        <a target="_self" href="registration.html"><font color="white">Register</font></a><font color="white"> </font><b><i><font color="white">Now!</font></i></b></td>
    </tr>
</table>
</form>
 
any help wood be greatly appreciated
thank you
ed
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: login code not working!

Post by califdon »

I don't see anything wrong in your code. I'd suggest that you echo the values in $username and $password to see what they contain, just before using them. If you ever use these scripts on a public server, you should do some checking of the values passed as POST variables before sending them to your database, though. That's the way many hacker attacks are perpetrated.
Post Reply