Page 1 of 1

Help with error message

Posted: Sun Nov 14, 2004 7:45 pm
by paqman
I am working on a main page for my website. Without going into too much detail, it keeps on saying that it finds an unexpected $, always on the last line of my file( I tried adding spaces to see what happened; always was on the last line of code). Does anyone have any idea what is going on? thanks

Posted: Sun Nov 14, 2004 7:53 pm
by scorphus
Help us help you. Please post the code (inbetween

Code: Select all

and
) and the full error message. Also consider reading this guide: Posting Code in the Forums.

-- Scorphus

Posted: Mon Nov 15, 2004 11:33 pm
by paqman
ok i figured you would need the code. It's really long. Basically it checks to see what resolution and what browser the user has and then includes files based on that.



Here's the code:


$error1 = " ";

$error2 = " ";

$error3 = " ";

$errormessage = "The file <b>".$loc."</b> doesn't exist. <br><br>
If you clicked a link to get here, please <a href=\"mailto:pgr@paqmangames.com?subject=TTS Broken Link&body=$loc\" target=\"_new\"><u>Report It Here</u></a>.";

$loc = $id.".html";


If ($browsername == "Netscape") {
If ($screenwidth >= 1024) {
echo $error1;
}
If ($screenwidth < 800) {
echo $error3;
}
}
If ($browsername == "Microsoft Internet Explorer") {
If ($screenwidth < 800) {
echo $error2;
}



If ($screenwidth == 800) {
include("index/index2_1.html");
if(!$php){
if($id) {
if(file_exists($loc))
{
echo $loc;
}
else {
echo $errormessage;
}
}
if($loc == ".html") {
echo "welcome.html";
}
}

if($php="1"){
$phploc = $id.".php";
if($id) {
if(file_exists($phploc))
{
echo $phploc;
}
}
}
include("index/index2_2.html");
}


If ($screenwidth >= 1024) {
include("index/index1_1.html");
if(!$php){
if($id) {
if(file_exists($loc))
{
echo $loc;
}
else {
echo $errormessage;
}
}
if($loc == ".html") {
echo "welcome.html";
}
}
if($php="1"){
$phploc = $id.".php";
if($id) {
if(file_exists($phploc))
{
echo $phploc;
}
}
}
include("index/index1_2.html");
}




$screenwidth and $browsername are variables which are already as cookies by a previous page. $id is in the web address. The basic format is for a page with a changeable window in the middle. I used photoshop to make a really 'pretty' layout. I removed the error messages to shorten this post. I'm sure it's just one too many brackets or something like that. If you have any ways for me to shorten the code using functions or something i would love to hear it.


THANKS

Posted: Tue Nov 16, 2004 7:37 am
by scorphus
Ok, now we have the source code, nice. But it seems to me that you forgot to check the Posting Code in the Forums topic.
As I wrote:(...) Please post the code (inbetween

Code: Select all

and
) (...) Also consider reading this guide: Posting Code in the Forums. (...)
Anyways, your code is missing an ending }, here it is, corrected (should be working now):

Code: Select all

<?php

$error1 = " ";

$error2 = " ";

$error3 = " ";

$errormessage = "The file <b>".$loc."</b> doesn't exist. <br><br>
If you clicked a link to get here, please <a href="mailto:pgr@paqmangames.com?subject=TTS Broken Link&body=$loc" target="_new"><u>Report It Here</u></a>.";

$loc = $id.".html";


If ($browsername == "Netscape")
{
	If ($screenwidth >= 1024)
	{
		echo $error1;
	}
	If ($screenwidth < 800)
	{
		echo $error3;
	}
}

If ($browsername == "Microsoft Internet Explorer")
{
	If ($screenwidth < 800)
	{
		echo $error2;
	}
	If ($screenwidth == 800)
	{
		include ("index/index2_1.html");
		if (!$php)
		{
			if ($id)
			{
				if (file_exists ($loc))
				{
					echo $loc;
				}
				else
				{
					echo $errormessage;
				}
			}
			if ($loc == ".html")
			{
				echo "welcome.html";
			}
		}
		if ($php = "1")
		{
			$phploc = $id.".php";
			if ($id)
			{
				if (file_exists ($phploc))
				{
					echo $phploc;
				}
			}
		}
		include ("index/index2_2.html");
	}
	If ($screenwidth >= 1024)
	{
		include ("index/index1_1.html");
		if (!$php)
		{
			if ($id)
			{
				if (file_exists ($loc))
				{
					echo $loc;
				}
				else
				{
					echo $errormessage;
				}
			}
			if ($loc == ".html")
			{
				echo "welcome.html";
			}
		}
		if ($php = "1")
		{
			$phploc = $id.".php";
			if ($id)
			{
				if (file_exists ($phploc))
				{
					echo $phploc;
				}
			}
		}
		include ("index/index1_2.html");
	}
}
?>
With best regards,
Scorphus.

Posted: Tue Nov 16, 2004 7:57 am
by scorphus
Hummm... taking a close look at your code, I figure out some errors:

Code: Select all

if ($php = "1")

Code: Select all

if ($php = "1")
This if condition of lines 54 and 88 will always evaluate to true. That's because it is an assignment, and this kind of assignment always return true. You should want to do this:

Code: Select all

if ($php == "1")

Code: Select all

if ($php == "1")
Also, you asked for a shorter code. I'll show you how you can achieve that, with the first part of your script, the rest stays up to you:

Code: Select all

&lt;?php
$error1 = " ";
$error2 = " ";
$error3 = " ";
$errormessage = "The file &lt;b&gt;".$loc."&lt;/b&gt; doesn't exist. &lt;br&gt;&lt;br&gt;
If you clicked a link to get here, please &lt;a href="mailto:pgr@paqmangames.com?subject=TTS Broken Link&amp;body=$loc" target="_new"&gt;&lt;u&gt;Report It Here&lt;/u&gt;&lt;/a&gt;.";
$loc = $id.".html";
if ($browsername == "Netscape")
	if ($screenwidth &gt;= 1024)
		echo $error1;
	else if ($screenwidth &lt; 800)
		echo $error3;
else if ($browsername == "Microsoft Internet Explorer") {
	if ($screenwidth &lt; 800)
		echo $error2;
	else if ($screenwidth == 800) {
?&gt;
This way it becomes shorter and a bit faster (because of some else's here and there).

-- Scorphus

Posted: Tue Nov 16, 2004 6:51 pm
by paqman
It worked perfectally. Sorry that I didn't read the php code rules. I will definetly come back to this forum when I have any problems in the future. Thanks again!!!