Jump to content

[SOLVED] Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING


Recommended Posts

Im creating a register page.

When i click on submit this is the error that im getting.

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/sites/nurevolution.co.uk/public_html/register.php on line 29

 

This is the script that i have used;

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Untitled Document</title>

</head>

 

<body>

 

<?php

 

//Database Information

 

$dbhost = "localhost";

$dbname = "your database name";

$dbuser = "username";

$dbpass = "yourpass";

 

//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 1 username=’$username’ and password=’$password’;  line 29

 

$result = mysql_query($query);

 

if (mysql_num_rows($result) != 1) {

$error = “Bad Login”;

    include “login.html”;

 

} else {

    $_SESSION[‘username’] = “$username”;

    include “memberspage.php”;

}

 

?>

 

</body>

</html>

 

 

Thanks for the help that you may be able to give me.

 

tecmeister

 

What's the error?

 

It is ok i have sorted that out now

 

In just having problems connection the mysql

 

I have changed the script to:

 

mysql_connect ("localhost","myusername","mypassword")or die("Could not connect: ".mysql_error());

mysql_select_db($dbname) or die(mysql_error());

 

what could the problem be?

 

Thanks for your help.

Looks like either your username or your password is incorrect.

 

I thought that but i have checked it over a few times.

 

I have put everything back to the default im now getting a error on:

 

Parse error: syntax error, unexpected T_VARIABLE in /home/sites/nurevolution.co.uk/public_html/register.php on line 31

 

$result = mysql_query($query);

 

Im sorry for all of the questions.

That is how much of a newbie i am.

do you need quotes around your query?

 

Im sorry i dont really know.

This is my first time doing this.

 

This is the website that im getting the script form:

http://www.swish-db.com/tutorials/view.php/tid/601

on the site the query is structured like this:

$query = "INSERT INTO users (name, email, username, password)

VALUES('$name', '$email', '$username', '$password')";

your query is missing these, try changing $query from

$query = your query;

to

$query = "your query"

 

don't forget the semi-colon like i just did

 

Yeah thanks done that one now.

 

Now to the other error that i had previously.

 

$error = “Bad Login”;

 

Parse error: syntax error, unexpected T_STRING in /home/sites/nurevolution.co.uk/public_html/register.php on line 34

 

don't forget the semi-colon like i just did

 

Thanks that worked.

 

Now we can sort out the previous error.

 

Parse error: syntax error, unexpected T_STRING in /home/sites/nurevolution.co.uk/public_html/register.php on line 34

 

$error = “Bad Login”;

Repost your script with all the changes you've made please.

 

Here is the script:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Untitled Document</title>

</head>

 

<body>

 

<?php

 

//Database Information

 

$dbhost = "localhost";

$dbname = "your database name";

$dbuser = "username";

$dbpass = "yourpass";

 

//Connect to database

 

mysql_connect ( 'localhost','web88-tecmeister','penalcoir')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 1 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”;

}

 

?>

 

</body>

</html>

First off, please put code in the code tags.

 

Change

$query = "select * FROM 'users' WHERE 1 username=’$username’ and password=’$password’";

to

$query = "select * FROM users WHERE 1 username='$username' and password='$password'";

Backdrops (`) should only go around column names.  Enclose variables in single quotes.  Backdrops aren't required in this case.

This should do it.  Include needs parenthesis (ex include("file.php"); )

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<?php

//Database Information

$dbhost = "localhost";
$dbname = "your database name";
$dbuser = "username";
$dbpass = "yourpass";

//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 1 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”);
}

?>

</body>
</html>

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.