Forum Moderators: coopster

Message Too Old, No Replies

Parse error: syntax error, unexpected T STRING

         

quazimodem

5:51 am on Mar 25, 2008 (gmt 0)

10+ Year Member



I am getting this error on a website that I inherited for support.

Parse error: syntax error, unexpected T_STRING in /home/website/public_html/includes/connection.inc.php on line 1

I'm not exactly sure what the problem is but I believe it's just a syntax problem. It worked before when we were running PHP v4.x but now we're running PHP v5.2.5 and the site is broken. Can anyone help?

This is the file:

<?php

function dbConnect() {

$user = "username";
$db = "database";
$pwd ="password";

$conn = mysql_connect('localhost', $user, $pwd) or die ('Cannot connect to server');
mysql_select_db($db) or die ('This command is not working, this is where it is breaking.');
return $conn;
}

?>

eelixduppy

5:59 am on Mar 25, 2008 (gmt 0)



What do you have on line 1 in that file? There is something missing from the code that you posted because I cannot find any errors there.

by the way, Welcome to WebmasterWorld! :)

quazimodem

6:15 am on Mar 25, 2008 (gmt 0)

10+ Year Member



I copied and pasted the entire contents of that file there. So not sure why I'm getting an error msg too.

And thanks for the welcome...

dreamcatcher

7:42 am on Mar 25, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You don`t by any chance have a space between <? and php do you? Just a thought. This forum may have removed the whitespace.

dc

quazimodem

3:38 pm on Mar 25, 2008 (gmt 0)

10+ Year Member



Nope. I double checked that using notepad2... there is no space. That whole first line is exactly 5 spaces before it goes to the next line.


<?php

function dbConnect() {

$user = "username";
$db = "database";
$pwd ="password";

$conn = mysql_connect('localhost', $user, $pwd) or die ('Cannot connect to server');
mysql_select_db($db) or die ('This command is not working, this is where it is breaking.');
return $conn;
}

?>

henry0

5:31 pm on Mar 25, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try this which works fine in 5++, I did not use that format since a while but I know for sure that it works fine.
in production and debug mode
remove the @

function db_connect()
{

$result = @mysql_pconnect("localhost", "my_username", "my_password");
if (!isset($result) && empty($result))
{echo "can't connect!"; }
if (!@mysql_select_db("my_DB"))
return false;
return $result;
}

usage:
<?php
$conn = db_connect();
?>

if it doesn't then we know that it comes from soemewhere else!

<edit>Typo</edit>

quazimodem

10:03 pm on Mar 25, 2008 (gmt 0)

10+ Year Member



wow. How bizarre was that. I just created a new file and copied/pasted the original code and the problem went away. I can't believe I didn't think about doing this before. I appreciate all the help and responses to my problem!

eelixduppy

10:53 pm on Mar 25, 2008 (gmt 0)



Glad you resolved your problem. There must have been a character in there that you didn't see that was causing problems for you.

ake15

2:02 pm on Mar 28, 2008 (gmt 0)

10+ Year Member



im gettin almost the same thing

<?php
if ($_SERVER['REQUEST_METHOD'] != 'POST'){
$me = $_SERVER['PHP_SELF'];
?>
<form name="form1" method="post"
action="<?php echo $me;?>">
<table border="0" cellspacing="0" cellpadding="2">
<tr>
<td><font face="Arial, Helvetica, sans-serif">Name:</font></td>
<td><input type="text" name="Name"></td>
</tr></br>
<tr>
<td><font face="Arial, Helvetica, sans-serif">E-mail:</font></td>
<td><input type="text" name="e-mail"></td>
</tr></br>
<tr>
<td valign="top"><font face="Arial, Helvetica, sans-serif">Phone:</font></td>
<td><input name="Phone" type="text" value=""></td>
</tr></br>
<tr>
<td><font face="Arial, Helvetica, sans-serif">Fax:</font></td>
<td><input type="text" name="Fax"></td>
</tr></br>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="Submit"
value="Send"></td>
</tr></br>
</table>
</form>
<p>
<?php
else {
error_reporting(0);
$recipient = 'aaron@example.com';
$from = stripslashes($_POST['Name']);
$e-mail = stripslashes($_POST['E-mail']);
$phone = stripslashes($_POST['Phone']);
$fax = stripslashes($_POST['Fax']);
if (mail($recipient, $name, $e-mail, $phone, $fax))
echo nl2br("<b>Message Sent:</b>
To: $recipient
Name: $name
E-mail: $e-mail
Phone: $phone
Fax: $fax
$msg");
else
echo "Message failed to send";
}
?>

i really dont know wuts goin on...some help please?

thanks

[edited by: eelixduppy at 4:09 pm (utc) on Mar. 28, 2008]
[edit reason] exemplified [/edit]