Jump to content

Parse error: syntax error, unexpected T_STRING in /home/webspace/public_html/Eri


erikn68

Recommended Posts

I am getting the error when I try to login.  Here is my login.php code

 

error message:  Parse error: syntax error, unexpected T_STRING in /home/webspace/public_html/Eri

 

 

$dbhost = "localhost";

$dbname = "webspace_eriknel1";

$dbuser = "webspace_er5";

$dbpass = "c6b7s9t1";

 

//Connect to database

 

<?php

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”;

}

 

?>

 

 

Link to comment
Share on other sites

session_start();

needs to go at the very top of your page, just after the <?php line.

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

has no opening double quote so your sting is totaly malformed and running into the rest of your code.

$dbpass = "c6b7s9t1";

Needs to be changed NOW!

Link to comment
Share on other sites

Another error

 

 

Parse error: syntax error, unexpected $end in /home/webspace/public_html/Erik.Nelson/login.php on line 32

 

This is line 32    ?>

 

All of the code, but I removed the db password for the forum

 

$dbhost = "localhost";

$dbname = "webspace_eriknel1";

$dbuser = "webspace_er5";

$dbpass = "";

 

//Connect to database

 

<?php

 

session_start();

 

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
Share on other sites

@OP: Seems that you are using several smart-quotes and apostrophes instead of regular double or single quotes in your code

 

$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
Share on other sites

error = 

Parse error: syntax error, unexpected T_STRING in /home/webspace/public_html/Erik.Nelson/login.php on line 33

Line 33 =  ini_set("display_errors", 1);

 

full code except dbpass

 

$dbhost = "localhost";

$dbname = "webspace_eriknel1";

$dbuser = "webspace_er5";

$dbpass = "";

 

//Connect to database

 

<?php

 

session_start();

 

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”;

}

error_reporting(E_ALL);

ini_set("display_errors", 1);

?>

Link to comment
Share on other sites

As mikosiko pointed out, you need to change all those wonky double quotes and apostrophes to real double quotes and single quotes.

 

Also, the error reporting stuff should be at the very top of your script.

 

EDIT: And unless you are running PHP5.4, that should be

error_reporting(E_ALL | E_STRICT); 

Link to comment
Share on other sites

and the error is?.... crystal ball is not available today.

 

to short this out a bit... here .... just copy/paste..... and answer/fix the commented questions

 

<?php
    error_reporting(E_ALL); 
    ini_set("display_errors", 1);


    session_start();
    
    $dbhost = "localhost";
    $dbname = "webspace_eriknel1";
    $dbuser = "webspace_er5";
    $dbpass = "";
    
    mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
    mysql_select_db($dbname) or die(mysql_error());

    // you MUST sanitize your input    
    $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";
        
        // What are yuu trying to do here... redirect to the user to the login page?
        // For that you must use header() not include()
        include "login.html";
    
    } else {
        $_SESSION['username'] = "$username";

        // What are yuu trying to do here... redirect to the user to the members page?
        // For that you must use header() not include()
        include "memberspage.php";
    }

?>

Link to comment
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.