Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

parse error with my PHP code

Status
Not open for further replies.

craigglenn

Technical User
Oct 30, 2003
42
0
0
US
I am receiving the following error in my php file. I have searched for syntax errors but just can put my finger on it.

Parse error: syntax error, unexpected T_VARIABLE in /home/content/b/a/r/barbmcvicker/html/includes/insert_tips_request.php on line 3


PHP code:

<?php
require_once("configuration.php");?
$jconfig = new JConfig();

$con = mysql_connect($jconfig->host, $jconfig->user, $jconfig->password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db($jconfig->db, $con);

$_first = $_POST['FirstName'];
$_last = $_POST['LastName'];
$_email = $_POST['Email'];
$regexp = "/^[^0-9][A-z0-9_]+([.][A-z0-9_]+)*[@][A-z0-9_]+([.][A-z0-9_]+)*[.][A-z]{2,4}$/";

$sql = "INSERT INTO jos_request (FirstName, LastName, Email, Request, DateCreated)
VALUES ('.mysql_real_escape_string($_first).','.mysql_real_escape_string($_last).','.mysql_real_escape_string($_email).','.mysql_real_escape_string('Newsletter and Tips').','.getdate().')";

if ($_first=$_last)
{
die('FirstName cannot be equal to LastName' . mysql_error());
}

if (preg_match($regexp, $_email))
{
mysql_query($sql);
}
else
{
die('Invalid Email Address' . mysql_error());
}

mysql_close($con);

?>

Thanks in advance for your help.

"You can have anything in life you want if you help enough people get what they want"
Zig Ziggler
 
Where is your JConfig class?

If you can't stand behind your troops, stand in front of them.
Semper Fidelis

Jim
 
In the configuration.php file that I included.



"You can have anything in life you want if you help enough people get what they want"
Zig Ziggler
 
i wonder whether you are using an old version of php?

i can see no syntax error in this text. please post configuration.php. quite probably there is no php close tag or a missing semicolon or similar

by the way this line will not work

Code:
if ($_first=$_last)

the = sign in php is an assignment operator. the comparison operators are == and ===

 
Nice catch jpadie. I am new to php. I will check the configuration.php file for errors. Don't think I should post it as it contains access var's to the site. I am using php 5 and mysql 5. Sorry for not giving that info up front.



"You can have anything in life you want if you help enough people get what they want"
Zig Ziggler
 
Just change the password and username to variables we just need to see the syntax you are using.

If you can't stand behind your troops, stand in front of them.
Semper Fidelis

Jim
 
configuration.php

<?php
class JConfig {
var $offline = '0';
var $editor = 'jce';
var $list_limit = '20';
var $helpurl = ' var $debug = '0';
var $debug_lang = '0';
var $sef = '0';
var $sef_rewrite = '1';
var $sef_suffix = '0';
var $feed_limit = '10';
var $feed_email = 'author';
var $secret = 'secret';
var $gzip = '0';
var $error_reporting = '-1';
var $xmlrpc_server = '0';
var $log_path = '/home/content/b/a/r/barbmcvicker/html/logs';
var $tmp_path = '/home/content/b/a/r/barbmcvicker/html/tmp';
var $live_site = ' var $force_ssl = '0';
var $offset = '-5';
var $caching = '0';
var $cachetime = '15';
var $cache_handler = 'file';
var $memcache_settings = array();
var $ftp_enable = '0';
var $ftp_host = '127.0.0.1';
var $ftp_port = '21';
var $ftp_user = '';
var $ftp_pass = '';
var $ftp_root = '/Joomla';
var $dbtype = 'mysql';
var $host = 'p50mysql99.secureserver.net';
var $user = 'UserName';
var $db = 'dbmcvicker';
var $dbprefix = 'jos_';
var $mailer = 'mail';
var $mailfrom = 'media@barbaramcvicker.com';
var $fromname = 'Barbara McVicker';
var $sendmail = '/usr/sbin/sendmail';
var $smtpauth = '0';
var $smtpsecure = 'none';
var $smtpport = '25';
var $smtpuser = '';
var $smtppass = '';
var $smtphost = 'localhost';
var $MetaAuthor = '1';
var $MetaTitle = '1';
var $lifetime = '60';
var $session_handler = 'database';
var $password = 'Password';
var $sitename = 'Barbara McVicker';
var $MetaDesc = 'Barbara McVicker is a nationally recognized eldercare expert, professional speaker, and author of &quot;Stuck in the Middle: Shared Stories And Tips For Caregiving Your Elderly Parents&quot;';
var $MetaKeys = 'barbara mcvicker, eldercare, elder care, caregiver, care giver, caregiving, care giving, parents, relatives, elderly, aging, alzheimer\'s, dementia, seniors, aarp, nursing home, hospital, assisted living, sandwich generation, baby boomer, boomer, stuck in the middle, advice, help, assistance, tips, support';
var $offline_message = 'BarbaraMcVicker.com is currently being upgrade and should be live by 1:30pm EST on 3/22. Until then, please go to for more information. Thank you!';
}
?>

"You can have anything in life you want if you help enough people get what they want"
Zig Ziggler
 
thanks. I see no particular problem in the jConfig class. I would advise changing the var keyword for public (as var is php 4 terminology and deprecated in php 5).

there are issues in the setting of the $sql variable. you are not correctly jumping in and out of double quotes. consider using printf and placeholders instead. it adds no functional enhancement but it does make it easier to spot problems.

Code:
$sql = "INSERT INTO jos_request 
		(FirstName, LastName, Email, Request, DateCreated)
		VALUES (
		'%s', '%s', '%s', '%s', '%s')";
$sql = sprintf(	$sql, 
				mysql_real_escape_string($_first), 
				mysql_real_escape_string($_last), 
				mysql_real_escape_string($_email),
				mysql_real_escape_string('Newsletter and Tips'),
				mysql_real_escape_string(getdate()));
 
thanks for the insight Jim. I will keep plugging away at it and give an update later. Thanks again for your time.

"You can have anything in life you want if you help enough people get what they want"
Zig Ziggler
 
jpadie,

Sorry, saw that on another post from jdhilljr! Got my programmers confused.

Thank you JPADIE and Jim(jdhilljr)!

Craig

"You can have anything in life you want if you help enough people get what they want"
Zig Ziggler
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top