Page 1 of 1
Parse Error
Posted: Fri Apr 21, 2006 10:14 pm
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();
Posted: Fri Apr 21, 2006 10:36 pm
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']')';
Re: Parse Error
Posted: Sat Apr 22, 2006 5:46 am
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']}')";
Posted: Mon Apr 24, 2006 12:55 pm
by cveselka
I already have that line in the code.
must be like this
Posted: Tue Apr 25, 2006 1:08 am
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();
Posted: Tue Apr 25, 2006 12:56 pm
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
Posted: Tue Apr 25, 2006 2:07 pm
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...
Posted: Tue Apr 25, 2006 2:15 pm
by cveselka
it's TO us mr. teacher