Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Newbie Parsing Problem
Old 08-13-2006, 06:58 PM Newbie Parsing Problem
Novice Talker

Posts: 9
Name: Larry
Trades: 0
Hey folks.

This is my real attempt at using php and I've run into a snag. I've put a flash form into a php-based template (soholaunch) and have cleaned up all errors but one.

Parse error
: parse error, unexpected '}' in /home/twoedged/public_html/myform.php on line 164


Here's the section of code where the error probably lies (sorry for the length):


}

if($unreg == 'true')

{
$unregMsg="<div align="center"><font size="1" face="Arial">Created with CoffeeCup Form Builder <a href="http://www.coffeecup.com" title="CoffeeCup Form Builder">Download It Here</a></font></div>";
$msg .= "------------------------\r\n\r\nThis Form was sent to you using CoffeeCup Form Builder.\r\nPlease tell a friend about us: http://www.coffeecup.com/form-builder\r\n";

else
{
$unregMsg = '';
}

$newMsg= $msg . $autoresponse;
//...... Construct a proper mime/UTF-8 for extended ASCII, and internationalization
$headers = "MIME-Version: 1.0\r\n" . "Content-type: text/plain; charset=UTF-8\r\n\r\n";

//...... If they specify "email" in their form, it will set the reply-to field.
)

The real problem is that I'm not really sure what I should be looking for. I can usually figure things out once I get familiar with them but just not there yet. Your help is muchly appreciated. Thanks.
webber is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-13-2006, 07:26 PM Re: Newbie Parsing Problem
Oneway's Avatar
Skilled Talker

Posts: 71
Trades: 0
I don't think you posted the code correctly.
Before the else should already be a } to close the if block.

Also, all double quotes except the opening and closing quotes should be escaped (like so: \" ) in the $unregMsg= line.

You can enclose php code into [ php] and [ /php ] tags (without the spaces) to preserve indentation and show syntax highlighting. This will make debugging easier for us.

Also, you've done good to include the error message, but if we don't know where line 164 is, we don't really know where to look, only that the problem is probably somewhere on or before line 164.

If the above suggestions don't remedy the problem, then it's probably best to include a bit more of the code up untill 164.
Oneway is offline
Reply With Quote
View Public Profile
 
Old 08-13-2006, 07:53 PM Re: Newbie Parsing Problem
Novice Talker

Posts: 9
Name: Larry
Trades: 0
Thanks. I'll try those and let you know shortly.

Quote:
{
$unregMsg="<div align="center"><font size="1" face="Arial">Created with CoffeeCup Form Builder <a href="http://www.coffeecup.com" title="CoffeeCup Form Builder">Download It Here</a></font></div>";
$msg .= "------------------------\r\n\r\nThis Form was sent to you using CoffeeCup Form Builder.\r\nPlease tell a friend about us: http://www.coffeecup.com/form-builder\r\n";
Can I simply cut this out?

The code I supplied was roughly around line 164 using an editor; don't have line count in the cpanel editor so I couldn't tell from that.

Last edited by webber; 08-13-2006 at 07:59 PM..
webber is offline
Reply With Quote
View Public Profile
 
Old 08-13-2006, 08:31 PM Re: Newbie Parsing Problem
Novice Talker

Posts: 9
Name: Larry
Trades: 0
I think I'm making progress here.

The original opening tag was < ? p and I couldn't find a closing tag so I changed the opening one to [ php ] and added the closing tag [ / php ]. (Without the spaces)

I tried the form. I received a page with a black background (not my design) and a link to CoffeeCup; that's it. No parsing error but no thank you page either.

It did send email to both the subscriber (me at another email address) and to me as the admin. However, it did not enter the data into the database.

This is the code from the beginning to where it joins the previous post.

/* Constants */
/* Version */ $version = '2.5';
/* Date */ $date = '1/22/06';
/* Error Level */ error_reporting(E_ALL & ~E_NOTICE);


$user="username"; (use actual username and password in file)
$password="password";
$database="twoedged_sope1";
mysql_connect(localhost,$user,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="CREATE TABLE contacts (id int(6) NOT NULL auto_increment,first varchar(15) NOT NULL,last varchar(15) NOT NULL,phone varchar(20) NOT NULL,mobile varchar(20) NOT NULL,fax varchar(20) NOT NULL,email varchar(30) NOT NULL,web varchar(30) NOT NULL,PRIMARY KEY (id),UNIQUE id (id),KEY id_2 (id))";
mysql_query($query);
mysql_close();

mysql_connect(localhost,$username,$password);

mysql_close();

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

mysql_query($query);

$NAME=$_POST['NAME'];
$EMAIL=$_POST['EMAIL'];
$HTML=$_POST['HTML'];
$TEXT=$_POST['TEXT'];

$query = "INSERT INTO MY_NEWSLETTER VALUES ('','$NAME','$EMAIL','$HTML','$TEXT',')";
mysql_query($query);

mysql_close();

//...... Added UTF-8 support

//Config file must be in the same directory as this file
//and have the same first part of the name. i.e. myform.inc.php
list($formName,$ext) = split('\.',basename($_SERVER['PHP_SELF']),2);
if (file_exists($formName.".inc.php"))
{
include($formName.".inc.php");
}

//XML file must be in the same directory as this file
$debug = (isset($_REQUEST['debug'])) ? $_REQUEST['debug'] : $debug;
if ($debug) error_reporting(E_ALL);

//...... Display debugging information
if ($debug)
{
switch($debug)
{
case 'info' :
phpinfo();
exit();
break;

case 'version' :
err("Current MailForm version: <b>".$version."</b><br>Current PHP version: <b>".phpversion()."</b><br> Current Revision Date: <b>$date</b>");
break;
}
}


$date=date("l, F dS, Y \a\\t g:i a");
$server=$_SERVER['SERVER_NAME'];

$msg="Here is the information submitted to $formName from $_SERVER[REMOTE_ADDR] on $date\r\n\r\n------------------------\r\n";

//...... Make sure we keep the variables
$subject = $_REQUEST['subject'];
$thankyoupage = $_REQUEST['thankyoupage'];
$xmlFile = $_REQUEST['xmlfile'];
$unreg = $_REQUEST['uR'];
$email = $_REQUEST['eM'];

if (file_exists($xmlFile))
{
$fd = fopen(basename($xmlFile),'r');
while(!feof($fd))
{
$contents .= fgets($fd,1024);
}
fclose($fd);
}
else
{
err("No &lt;xml&gt; data file found<br>Please upload the data xml file ".$_REQUEST['xmlfile']);
}

$file_info = preg_replace("/\r|\n/"," ",$contents);

//...... Includes the form results in your thank you page
$incresults = (preg_match('/<form.*?includeresults="true".*?>/',$file_info));

//...... Sends email of form results to the user
$emailusr = (preg_match('/<form.*?emailuser="true".*?>/',$file_info));

preg_match('/<hidden.*?name="mailto".*?value="(.*?)".*?>/',$file_info,$matches);
$mailto = $matches[1];

preg_match('/<hidden.*?name="thankyoumessage".*?value="(.*?)".* ?>/',$file_info,$matches2);
$thanksMsg = unhtmlentities($matches2[1]);


preg_match('/<form.*?bkcolor2="(.*?)".*?>/',$file_info,$matches3);
$backgroundclr = $matches3[1];

preg_match('/<form.*?fontcolor2="(.*?)".*?>/',$file_info,$matches4);
$fontclr = $matches4[1];

preg_match('/<form.*?autoresponse="(.*?)".*?>/',$file_info,$matches5);
$autoresponse = $matches5[1];

if(!$thanksMsg)
{
$thanksMsg="Thank you for your form submission!";
}

if(!$subject)
{
$subject="Form Submission";
}


//...... Reversing array elements so they appear in correct form order
$_REQVARS = array_merge($_POST,$_GET);

//...... Delete them from the request array, we won't need
//...... to send these in the actual email.
unset($_REQVARS['thankyoupage']);
unset($_REQVARS['subject']);
unset($_REQVARS['mailto']);
unset($_REQVARS['xmlfile']);
unset($_REQVARS['thankyoumessage']);
unset($_REQVARS['uR']);
unset($_REQVARS['eM']);


$addtoThank.="<span><p align=\"center\">Below is the information you submitted:</br></br></p><p align=\"center\">";
$txtmsg=$formName.'|'.date("Y-m-d H:i:s").'|'.$_SERVER['REMOTE_ADDR'].'|';

$_REQVARS=array_reverse($_REQVARS);

foreach($_REQVARS as $key=>$value)
{
$new1=str_replace("_"," ",$key);
$msg .= "$new1: ".stripslashes($value)."\r\n\r\n";
$addtoThank.="$new1: ".stripslashes($value)."<br/>";
$txtmsg .= "$new1: ".stripslashes($value)."|";
}

$addtoThank.="</p></span>";
$addtoThank=str_replace("_"," ",$addtoThank);

}

if($unreg == 'true')

Thanks.

Last edited by webber; 08-13-2006 at 08:35 PM..
webber is offline
Reply With Quote
View Public Profile
 
Old 08-13-2006, 08:53 PM Re: Newbie Parsing Problem
Oneway's Avatar
Skilled Talker

Posts: 71
Trades: 0
Whoa.. I think you misunderstood.. The [ php ] tags are meant only for posting the code here on the forums (to increase readability). You shouln't put them instead of the <?php and ?> tags in your code..

First, remove the && ~E_NOTICE from your error reporting setting. It will probably reveal some interesting notices.

Second, this is what you're doing in the first 20 lines or so.
- set variables for username , password and databsename - OK
- connect to database server - OK
- select database -OK
- create a new table contacts - WTF? Do you realise this is called every time the page is loaded and thus clearing all data already inside the table?
- close mysql connection - OK
- open mysql connection - STRANGE, BUT OK
- close mysql connection - GETTING VERY REDUNDANT

From here on you never open the mysql connection again, so it's pretty obvious why data isn't being written to the database.

So, remove the close,open,close statements and place a close mysql statement at the end of the script (or don't, php will automatically close it for you when the script finishes running)

Let's see where that gets us
Oneway is offline
Reply With Quote
View Public Profile
 
Old 08-13-2006, 09:27 PM Re: Newbie Parsing Problem
Novice Talker

Posts: 9
Name: Larry
Trades: 0
[quote=Oneway;273228]Whoa.. I think you misunderstood.. [/qoute]

I did thanks.

Quote:
- create a new table contacts - WTF? Do you realise this is called every time the page is loaded and thus clearing all data already inside the table?
No, I didn't. So the only time to use that would be in a separate file and called to create a new table, right?


Quote:
From here on you never open the mysql connection again, so it's pretty obvious why data isn't being written to the database.
That makes sense.

I tried it again and get another parsing error:
Parse error: parse error, unexpected T_VARIABLE in /home/twoedged/public_html/myform.php on line 10

I gather that means an unexpected text variable. In which case I've used the wrong elements as variables. The line 10 error puts it right about where the variables to post are. This scipt calls a xml file and I took the variables from there. Here's a sample:


<label
name="My Text 2"
x="19"
y="39"
w="77"
h="12"
text="Your Name:"
fontbold="bold"
fontitalic="italic"
fontname="Arial"
fontcolor="0xFFFFFF"
fontsize="10"
></label>

<textinput
name="Name"
x="19"
y="55"
w="140"
h="20"
initvalue=""
bkcolor="0xFFFFFF"
fontname="Arial"
fontcolor="0x000000"
required="true"
>
</textinput>

What do I use in here as the variable to post to the database? This should be the last glitch.
Oh, two of the compenents for data are the form the subscriber wants to receive email in, i.e. HTML or TEXT. Does this cause a problem? If it does I'll just eliminate the option.

Last edited by webber; 08-13-2006 at 09:30 PM..
webber is offline
Reply With Quote
View Public Profile
 
Old 08-14-2006, 06:26 AM Re: Newbie Parsing Problem
Oneway's Avatar
Skilled Talker

Posts: 71
Trades: 0
Quote:
Originally Posted by webber View Post
No, I didn't. So the only time to use that would be in a separate file and called to create a new table, right?
Correct.

Quote:
Originally Posted by webber View Post
I tried it again and get another parsing error:
Parse error: parse error, unexpected T_VARIABLE in /home/twoedged/public_html/myform.php on line 10

I gather that means an unexpected text variable. In which case I've used the wrong elements as variables. The line 10 error puts it right about where the variables to post are. This scipt calls a xml file and I took the variables from there. Here's a sample:
Unexpected T_VARIABLE tells you the PHP-parser encountered a text chracter where something else was expected. This error is often caused by not ending the previous line with a ;
If you post lines 9 and 10 it'll be easier to find the trouble. (And i'm afraid i don't know much about XML IF it turns out that your problem is there.)
Oneway is offline
Reply With Quote
View Public Profile
 
Old 08-14-2006, 08:48 AM Re: Newbie Parsing Problem
Novice Talker

Posts: 9
Name: Larry
Trades: 0
Quote:
Originally Posted by Oneway View Post
Unexpected T_VARIABLE tells you the PHP-parser encountered a text chracter where something else was expected. This error is often caused by not ending the previous line with a ;
The only place I would question is after VALUES there is no ; in the originial file.

Quote:
If you post lines 9 and 10 it'll be easier to find the trouble. (And i'm afraid i don't know much about XML IF it turns out that your problem is there.)
My second to last post has the code from the beginning. The one where I got slammed for all the opening/closing statements.

Do you want me to repost them after I cleaned them up?
webber is offline
Reply With Quote
View Public Profile
 
Old 08-14-2006, 10:53 AM Re: Newbie Parsing Problem
Oneway's Avatar
Skilled Talker

Posts: 71
Trades: 0
Quote:
Originally Posted by webber View Post
Do you want me to repost them after I cleaned them up?
Yeah, please. I've got no idea how it looks now. And please put the code between [ php] [ /php ] tags in your post. The read is so much better that way.

You talk about opening an XML file, but in your second to last post this only happenes well after line 75. So they shouldn't be te cause of the error on line 10. Did you cut that much in the code or am i completely misunderstanding?
Oneway is offline
Reply With Quote
View Public Profile
 
Old 08-14-2006, 08:26 PM Re: Newbie Parsing Problem
Novice Talker

Posts: 9
Name: Larry
Trades: 0
Quote:
Originally Posted by Oneway View Post
Yeah, please. I've got no idea how it looks now. And please put the code between [ php] [ /php ] tags in your post. The read is so much better that way.
Gotcha. Won't make that mistake again.
PHP Code:
Constants   */
/* Version     */ $version '2.5';
/* Date           */ $date '1/22/06';
$user="username";
$password="password";
$database="twoedged_sope1";
mysql_connect(localhost,$user,$password);
@
mysql_select_db($database) or die( "Unable to select database");

mysql_query($query);


mysql_connect(localhost,$username,$password);


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



$name=$_POST['Name'];
$email=$_POST['Email'];
$HTML=$_POST['HTML'];
$TEXT=$_POST['TEXT'];


$query "INSERT INTO MY_NEWSLETTER VALUES 
('','
$Name','$Email','$HTML','$TEXT',"); 
Quote:
You talk about opening an XML file, but in your second to last post this only happenes well after line 75. So they shouldn't be te cause of the error on line 10. Did you cut that much in the code or am i completely misunderstanding?
That may very well be the problem though. It's out of sequence. I'm asking the code to post data that it doesn't have access to yet. I've just come online so I'm going to move that section to after where the XML is called; the file is called, the data collected and then posted. Should work. I'll be right back.

Last edited by webber; 08-14-2006 at 08:38 PM..
webber is offline
Reply With Quote
View Public Profile
 
Old 08-15-2006, 09:11 AM Re: Newbie Parsing Problem
Oneway's Avatar
Skilled Talker

Posts: 71
Trades: 0
You have these lines twice in your code:

PHP Code:
mysql_connect(localhost,$user,$password);
@
mysql_select_db($database) or die( "Unable to select database"); 
You don't have to re-open the connection after executing a query. Even worse, this way you now have two connections open.
It's common in a php script to open the connection at the beginning of the script, do whatever and how many queries are nessecary and then at the end close the connection (or let PHP handle the closing).

So, lose the reopening and selecting of the database for the second time and change the remaining line:
PHP Code:
mysql_connect(localhost,$user,$password); 
into:
PHP Code:
mysql_connect('localhost',$user,$password); 
That is probably where the unexpected T_VARIABLE came from.

Oneway is offline
Reply With Quote
View Public Profile
 
Old 08-15-2006, 09:52 AM Re: Newbie Parsing Problem
Novice Talker

Posts: 9
Name: Larry
Trades: 0
Okay. Tried that and still receive the error message. Also verified with 3 browsers after dumping cache just to be sure. Here's the current code:

PHP Code:
/* Constants   */
/* Version     */ 
$version '2.5';
/* Date           */ $date '1/22/06';

$user="username";
$password="password";
$database="twoedged_sope1";
mysql_connect('localhost',$username,$password);
@
mysql_select_db($database) or die( "Unable to select database"); 
mysql_query($query);

//...... Added UTF-8 support

//Config file must be in the same directory as this file
//and have the same first part of the name. i.e. myform.inc.php
list($formName,$ext) =  split('\.',basename($_SERVER['PHP_SELF']),2);
if (
file_exists($formName.".inc.php"))
{
        include(
$formName.".inc.php");

Here's the page:
Welcome to Two-Edged Sword!

Last edited by webber; 08-15-2006 at 10:06 AM..
webber is offline
Reply With Quote
View Public Profile
 
Old 08-15-2006, 10:05 AM Re: Newbie Parsing Problem
Oneway's Avatar
Skilled Talker

Posts: 71
Trades: 0
The first time this line occurs (right after selecting the database), $query isn't defined yet. That doesn't explain the error, but i think this is a remnant from all the editing you did.
PHP Code:
mysql_query($query); 
Tell you what, i'll pm you my email address and if you want you can send the file to me and i'll give it a good once over to see what all the trouble is.
Oneway is offline
Reply With Quote
View Public Profile
 
Old 08-15-2006, 10:29 AM Re: Newbie Parsing Problem
Novice Talker

Posts: 9
Name: Larry
Trades: 0
Okay. Thanks.

<font color="#000000">I have a couple of questions about these lines:

PHP Code:
if (file_exists($formName.".inc.php"))
{
        include(
$formName.".inc.php");

1. The file is called myform.php so should the include be deleted?
2. Is there supposed to be a period after Name?
3. At the end of the first line there is a closing brace and not a semi-colon, is this a problem?


Last edited by webber; 08-15-2006 at 10:57 AM..
webber is offline
Reply With Quote
View Public Profile
 
Old 08-15-2006, 11:31 AM Re: Newbie Parsing Problem
Oneway's Avatar
Skilled Talker

Posts: 71
Trades: 0
If you mean that the file you want to include is called 'myform.php' and $formName has that value 'myform.php' then your code should look like this:
PHP Code:
if (file_exists($formName)) {
        include(
$formName);

Otherwise the file php would try to include is: myform.php.inc.php
Notice the curly braces at the end of the first line.
You can also put them on the next line if you wish but this illustrates the reason there is no semicolon at the end:
the if(....) { is the conditional opening of a block of statements, not a statement in itself.
Semicolons only go after statements:
PHP Code:
$varname "value";
openDir("dirname"); 
I received the file okay and will be taking a look at it later. (might take a few hours, work just popped up.)
Oneway is offline
Reply With Quote
View Public Profile
 
Old 08-15-2006, 02:19 PM Re: Newbie Parsing Problem
Ultra Talker

Posts: 483
Trades: 0
Quote:
Otherwise the file php would try to include is: myform.php.inc.php
Actually I don't think that's correct... if you look at the line above it:
PHP Code:
list($formName,$ext) =  split('\.',basename($_SERVER['PHP_SELF']),2); 
you will see that $formName is the filename without the '.php' extension. Hence, it would include myform.inc.php.
TwistMyArm is offline
Reply With Quote
View Public Profile
 
Old 08-17-2006, 10:21 AM Re: Newbie Parsing Problem
Novice Talker

Posts: 9
Name: Larry
Trades: 0
Quote:
Originally Posted by TwistMyArm View Post
Actually I don't think that's correct... if you look at the line above it:
PHP Code:
list($formName,$ext) =  split('\.',basename($_SERVER['PHP_SELF']),2); 
you will see that $formName is the filename without the '.php' extension. Hence, it would include myform.inc.php.
I need clarification on this. This file is called myform.php so this file is actually calling itself to run which is why the include is there, correct? So then why would it be myform.inc.php and not myform.php.inc.php?

Thanks.

Just reread your post. Am I correct is saying the first php is unnecessary because this variable $ext covers that?

Last edited by webber; 08-17-2006 at 10:27 AM..
webber is offline
Reply With Quote
View Public Profile
 
Old 08-18-2006, 11:07 AM Re: Newbie Parsing Problem
Ultra Talker

Posts: 483
Trades: 0
From what I can see, the code is basically including a (possibly configuration?) file that is specific to that particular file.

The line:
list($formName,$ext) = split('\.',basename($_SERVER['PHP_SELF']),2);

Basically takes the file name that is being used and splits it in to to variables: $formName, which is set to 'myform' and $ext, which is set to 'php'.

That's why when you do:
include($formName.".inc.php");

It's trying to include myform.inc.php.

That's about as easy as I can explain it... so I'm hoping that that's what you were asking
TwistMyArm is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Newbie Parsing Problem
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.55907 seconds with 12 queries