Forum Moderators: coopster

Message Too Old, No Replies

Where's the problem.

Parse error: parse error, unexpected T_ECHO in /home/connection.php on l

         

Conscientious Reject

12:01 am on Dec 26, 2005 (gmt 0)

10+ Year Member



Now, I am having problems with my connection script. I am about to post a new topic. It's easy enough:

Parse error: parse error, unexpected T_ECHO in /home/mysql_connect.php on line 31

but no matter where I look - even line 31 - I can't seem to find what this means. I am including my entire script.

<?php # Script 12.4 - mysql_connect.php
// This file contains the database access information. This file also establishes a connection to MySQL and selects the database.
// Set the database access information as constants.
define ('DB_USER', 'me');
define ('DB_PASSWORD', 'mypassword');
define ('DB_HOST', 'localhost');
define ('DB_NAME', 'myDBname');
if ($dbh=mysql_connect (DB_HOST, DB_USER, DB_PASSWORD)) {
// Make the connnection.
if (!mysql_select_db (DB_NAME)) {
// If it can't select the database.
// Handle the error.
my_error_handler (mysql_errno(), 'Could not select the database: ' . mysql_error());
// Print a message to the user, include the footer, and kill the script.
echo '<p><font color="red">The site is currently experiencing technical difficulties. We apologize for any inconvenience.</font></p>';
include_once ('footer.html');
exit();
} // End of mysql_select_db IF.
} else {
// If it couldn't connect to MySQL.
// Print a message to the user, include the footer, and kill the script.
my_error_handler (mysql_errno(), 'Could not connect to the database: ' . mysql_error())

//this is line 31.
echo '<p><font color="red">The site is currently experiencing technical difficulties. We apologize for any inconvenience.</font></p>';
//end of line 31

include_once ('footer.html');
exit();

} // End of $dbc IF.
// Function for escaping and trimming form data.
function escape_data ($data) {
global $dbc;
if (ini_get('magic_quotes_gpc')) {
$data = stripslashes($data);
}
return mysql_real_escape_string (trim ($data), $dbc);
} // End of escape_data() function.?>

I am becoming quite the regular here at this discussion board. I really need all the help I can get.

Thanks
Mitchell

henry0

12:50 am on Dec 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi again :)

I will do
but it's just me
echo " "; I like it better than echo 'aaaa';
so use double quote.

Then did you by any chance add a font color to the original script?
Try either to esacape the double quote \"red\"
or make a rule of using single quote
'red'

Span

1:14 am on Dec 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Should there be a semicolon at the end of this line?

my_error_handler (mysql_errno(), 'Could not connect to the database: ' . mysql_error())

yes

ergophobe

5:34 pm on Dec 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Have a look at the forum charter [webmasterworld.com]

There is a link there to a thread on troubleshooting (Troubleshooting 101). Probably the most important skill you can learn early on. Troubleshooting can be incredibly aggravating, but with a good skill set, it can be fairly efficient (though always unpredictable). Anyway, I think if you read that thread and follow the links there, you'll have a good handle on how to answer these questions for yourself. This is important because you'll likely move on to scripts where the problems are harder to identify (logic errors that are way upstream of where the problem occurs), so it's good to cut your teeth on troubleshooting your own parse error problems as you'll learn the skill of finding the problem (the fix is usually easy).

One thing you may have already learned from this thread - parse errors are very often caused by something that is one or more lines upstream. If the problem is a missing quote mark, it could be WAY upstream and the script doesn't blow up until it finds the next quote mark. The missing semi-colon that causes an error on the next PHP line down is very common.

BTW About 22 years ago, I once had a dream that I was trying to tell someone something but he kept staring back at me blankly with no comprehension because I kept forgetting the semi-colon in my sentence (I was wokring day and night on a big project in Pascal at the time, which also requires semicolons at the end of statements).

Conscientious Reject

4:13 am on Dec 27, 2005 (gmt 0)

10+ Year Member



Thanks everyone,

Well, I finally moved on, and fixed it. You guys were right. I just forgot the ";". Now I have another chicken to fry. Still, I am going to take ergophobe's advice. Actually, I am glad to finally see a place where I can get some good input. In the mean time I'll fill you guys in on my next gripe. I am getting this:

An error occurred in script /home/landingh/public_html/config.inc on line 13: mysql_real_escape_string() expects parameter 2 to be resource, null given.

When I try to run my register.php through a configuration script like this:

<?php # Script 12.3 - config.inc

// This script sets the error reporting and logging for the site.

//error_reporting (0);
// Production level
error_reporting (E_ALL); // Development level

// Use my own error handling function.

function my_error_handler ($e_number, $e_message) {

$message = 'An error occurred in script ' . __FILE__ . ' on

line ' . __LINE__ . ": $e_message";
//error_log ($message, 1, 'myemail@browser.com'); // Production (send email)
echo '<font color="red" size="+1">', $message, '</font>';
//Development (print the error in red)
}
set_error_handler('my_error_handler');

?>

Anyway, I ll chat later.

Thanks for all the help.