Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.