Parse Error

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
cveselka
Forum Newbie
Posts: 8
Joined: Wed Apr 19, 2006 1:06 pm

Parse Error

Post by cveselka »

I'm getting the below error:
Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in users.php on line 12

Here's the code

Code: Select all

<?php

$DBHOST = 'localhost';
$DBUSER = '*******';
$DBPASS = '******';
$DBNAME = '*********';

if($_POST['submit']);

$dbconnect = mysql_connect($DBHOST,$DBUSER,$DBPASS) or die('Err:Unable to connect to database');

@mysql_select_db($DBNAME) or die('Unable to select database ''.$dbname');

$sqlquery = 'INSERT INTO Users (LastName,emailaddress) VALUES ('.$_POST['LastName'].','.$_POST['emailaddress']')';

$results = mysql_query($sqlquery)or die ('Could not insert record into db:' . mysql_error());
mysql_close();
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Check your single quotes in this line:

Code: Select all

@mysql_select_db($DBNAME) or die('Unable to select database ''.$dbname');
Edit:
And this line:

Code: Select all

$sqlquery = 'INSERT INTO Users (LastName,emailaddress) VALUES ('.$_POST['LastName'].','.$_POST['emailaddress']')';
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Re: Parse Error

Post by timvw »

Since you're using strings delimited with single quotes ' ... ' you need to escape all single quotes in between.. As explained in the strings section in the manual.


Btw, you are not validating input at all..
And you are not preparing that input for use in a (my)sql query either.. (http://www.php.net/mysql_real_escape_string)
What would happen if your name was "John O'Reilly?".

I usually find it easier to use double quotes when variables are involved

Code: Select all

die("Unable to select database '$dbname'");
$query = "INSERT INTO Users (Lastname, emailaddress) VALUES ('{$_POST['LastName']}', '{$_POST['emailaddress']}')";
cveselka
Forum Newbie
Posts: 8
Joined: Wed Apr 19, 2006 1:06 pm

Post by cveselka »

I already have that line in the code.
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

must be like this

Post by dibyendrah »

You must use double quote insted of single quote.

Code: Select all

<b><?php

$DBHOST = 'localhost';
$DBUSER = '*******';
$DBPASS = '******';
$DBNAME = '*********';

if($_POST['submit']);

$dbconnect = mysql_connect($DBHOST,$DBUSER,$DBPASS) or die('Err:Unable to connect to database');

@mysql_select_db($DBNAME) or die("Unable to select database ".$dbname);

$sqlquery = "INSERT INTO Users (LastName,emailaddress) VALUES ('".$_POST['LastName']."','".$_POST['emailaddress']."')";

$results = mysql_query($sqlquery) or die ("Could not insert record into db:" . mysql_error());
mysql_close();
cveselka
Forum Newbie
Posts: 8
Joined: Wed Apr 19, 2006 1:06 pm

Post by cveselka »

Okay now I'm getting it for line 14

Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/garagesa/public_html/php/users.php on line 14
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

cveselka wrote:Okay now I'm getting it for line 14

Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/garagesa/public_html/php/users.php on line 14
Well, now you can proove us what you've learned...
cveselka
Forum Newbie
Posts: 8
Joined: Wed Apr 19, 2006 1:06 pm

Post by cveselka »

it's TO us mr. teacher
Post Reply