Jump to content

Stupid error..


Kerotan

Recommended Posts

Im new to php/mysql and trying to learn it etc.

 

I tried to do a login script thingy for a website but im having problems when the user trys to log in :S

 

Error:

Parse error: syntax error, unexpected T_STRING in C:\wamp\www\login.php on line 19

 

login.php

<?php

//Database Information

$dbhost = "localhost";
$dbname = "war";
$dbuser = "root";
$dbpass = "****";

//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 users 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 “memberspage.php”;
}

?>

 

Anyone know what the problem is and how i fix it? :S

 

Link to comment
https://forums.phpfreaks.com/topic/73026-stupid-error/
Share on other sites

 

$query = “select * from users where username=’$username’ and password=’$password’”;

$query = "select * from users where username='$username' and password='password'";

 

use "" or '

 

Thanks for the quick response but..

 

I dont get you :P

 

Use "" or ' were or instead of what? lol..

Link to comment
https://forums.phpfreaks.com/topic/73026-stupid-error/#findComment-368272
Share on other sites

try and tell us the error

<?php
session_start();
$dbhost = "localhost";
$dbname = "war";
$dbuser = "root";
$dbpass = "****";
mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());

$username = $_POST['username'];
$password = md5($_POST['password']);

$query = "select * from users 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 'memberspage.php';
}

?>

Link to comment
https://forums.phpfreaks.com/topic/73026-stupid-error/#findComment-368283
Share on other sites

I have a couple tips that you could use to make you coding a little easier.

 

1st: Create a connect.php file and include it (it just looks nicer and less cluttered and changes happen in one place)

2nd Do a header("location: page.php"); instead of an include

3rd Don't use html or htm extensions because later on you may want to do some php in those pages and then you will have to change them.

Link to comment
https://forums.phpfreaks.com/topic/73026-stupid-error/#findComment-370846
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.