Forum Moderators: coopster

Message Too Old, No Replies

PhP Script problem (paradox)

         

omoutop

12:59 pm on Jul 8, 2005 (gmt 0)

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



Hi to all

I have the script presented below which returns the message:

Parse error: parse error, unexpected $ in ......../demo.php on line 1

I can not understand where is the fault and i have tried lots of things to locate it and fix it....
ANY SUGGESTIONS?

the paradox is that the fault is located in line 1 by the browser which means that either the fault is in line 1, or it is somewhere else and it cant be located by browser........confusing

<?
include "dbconnect.php";
$type = ($_REQUEST ['type']);
if (!$db_conn) {
echo '<p>&nbsp;</p>';
echo '<p>&nbsp;</p>';
echo '<div align="center" class="greeka">An error has occured, Database can not be reached, please try again later. <p>';
echo '<p>&nbsp;</p>';
echo '<p>&nbsp;</p>';
} else {
// Set some variables for script
// To show each page by number set to Y. Set to N for prev-next links only

$showpages = "Y";

// Set number of records to be displayed per page $limit=somenumber
$limit=5;

if (empty($offset)) $offset=0;

$query = 'select * from Hotels '
."where type = '$type'";
$result = mysql_query($query);
$numrows = mysql_num_rows($result);
if ($numrows==0) {
echo '<p>&nbsp;</p>';
echo '<p>&nbsp;</p>';
echo '<div align="center"> We are sorry, there is not any available record to display! </div>';
echo '<p>&nbsp;</p>';
echo '<p>&nbsp;</p>';
} else
?>
<div align=center>
<strong><? echo $type?></strong>
</div>

<?
echo '<p>&nbsp;</p>';
echo '<p>&nbsp;</p>';
{
$query = 'select * from Hotels '

."where type = '$type' limit $offset,$limit";
$result2 = mysql_query($query2);
while ($row=mysql_fetch_assoc($result2)) {

$ID = $row['ID'];
$name = $row['name'];
$hoteldescr = $row['hoteldescr'];
$location = $row['location'];
$town = $row['town'];
$url = "http://www.example.gr/nikos/bestour/";
$url2 = "http://www.example.gr/nikos/bestour/pictures/";
$querypicture = "select * from Gallery where HotelID = '$ID'";
$resultpicture = mysql_query($querypicture);
while ($rowpicture=mysql_fetch_assoc($resultpicture)) {
$picture = $rowpicture['picture'];
$descritpion = $rowpicture['descritpion'];
?>
<table width="73%" border="3" align="center" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF">
<tr bgcolor="#FFFFFF">
<td width="21%" rowspan="2" bordercolor="#FFFFFF" bgcolor="#0d9aef"><div align="center"><img src="<? echo $url2?><? echo $picture?>" alt="<? echo $descritpion?>" width="150" height="113"></div></td>
<td width="43%" height="45" bordercolor="#FFFFFF"><div align="center">Location: <? echo $location?> </div></td>
<td width="36%" bordercolor="#FFFFFF"><div align="center">Town: <? echo $town?></div></td>
</tr>
<tr>
<td height="78" colspan="2" bordercolor="#0d9aef"><div align="justify"><? echo $hoteldescr?></div></td>
</tr>
</table>
<?

};
};

//determine number of pages needed
$pages=intval($numrows/$limit);

//if number of records isn't evenly divisible by the number of pages above, add another page.
if ($numrows%$limit) {
$pages++;
}

//set value of first record to be displayed
$first_record = $offset + 5;
echo "<br />";

//see if we're on the last page
if (!((($offset)/$limit)+1==$pages)) {
$last_record = $offset + $limit;

//is last page
echo " <strong>$last_record</strong> of <strong>$numrows</strong> $type(s). Click on image to view the $type <br />";
} else {
//is NOT last page - send this to browser
echo " <strong>$numrows</strong> of <strong>$numrows</strong> $type(s). Click on image to view the $type<br>";
}

echo "<br />\n";

//prepare and display links to other results in browser
if ($offset!= 0) {
$prevoffset=$offset-$limit;

//create a previous link - if we're not on the first page
echo "<a class='nav' href='$PHP_SELF?offset=$prevoffset'>&lt;&lt;&nbsp;Prev</a> &nbsp; \n";
}

//construct that shows just prev-next or all page numbers

if ($showpages == Y) {
if ( $pages!= 1 ) {
for ($i=1;$i<=$pages;$i++) {
$newoffset=$limit*($i-1);
if ( ((($offset)/$limit)==($i-1)) ) {
echo "$i &nbsp; \n";
} else {
echo "<a class='nav' href='$PHP_SELF?offset=$newoffset'>$i</a> &nbsp; \n";
}
}
}
}

if (!((($offset)/$limit)+1==$pages) && $pages!=1) {
$newoffset=$offset+$limit;

//create a next link - if we're not on the last page
echo ("<a class='nav' href='$PHP_SELF?offset=$newoffset'>Next&nbsp;&gt;&gt;</a><p>\n");
}
} else {
echo "No more $type(s) to display!";
}
}
?>

[edited by: jatar_k at 4:41 pm (utc) on July 8, 2005]
[edit reason] examplified urls and compressed code [/edit]

Angelis

1:08 pm on Jul 8, 2005 (gmt 0)

10+ Year Member



Might be the db_connect.php file with the error, what are the contents of that file (Obviously remove your username / password etc).

omoutop

1:14 pm on Jul 8, 2005 (gmt 0)

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



<?
@ $db_conn = mysql_connect('localhost', '-u', '-p');
mysql_select_db('DATABASE', $db_conn);
?>
this is the db_connect.php which works with every other script...
I have even tried to delete the include db_connect row from the problematic script and call the connections manually....same problems....

Angelis

1:18 pm on Jul 8, 2005 (gmt 0)

10+ Year Member



Is there any particular reason for the @ symbol in the script?

omoutop

1:28 pm on Jul 8, 2005 (gmt 0)

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



I dont remember the reason...but most script have the @ symbol before connecting to the DBserver...anyway...i tried it without @ and I still get the line 1 error....

coopster

1:37 pm on Jul 8, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Try commenting out portions of your code and keep narrowing it down until you can nail it down to a certain block. I notice one area where you may run into another parse error:
if ($showpages == Y)

Angelis

1:42 pm on Jul 8, 2005 (gmt 0)

10+ Year Member



Had a look through the entire script, there was a few errors within the code so I fixed them.

<?
include "dbconnect.php";
$type = ($_REQUEST ['type']);
if (!$db_conn)
{
echo '<p>&nbsp;</p>';
echo '<p>&nbsp;</p>';
echo '<div align="center" class="greeka">An error has occured, Database can not be reached, please try again later. <p>';
echo '<p>&nbsp;</p>';
echo '<p>&nbsp;</p>';
}

else
{

// Set some variables for script
// To show each page by number set to Y. Set to N for prev-next links only

$showpages = "Y";

// Set number of records to be displayed per page $limit=somenumber
$limit=5;

if (empty($offset))
{
$offset=0;
}
$query = 'select * from Hotels '

."where type = '$type'";
$result = mysql_query($query);
$numrows = mysql_num_rows($result);
if ($numrows==0)
{
echo '<p>&nbsp;</p>';
echo '<p>&nbsp;</p>';
echo '<div align="center"> We are sorry, there is not any available record to display! </div>';
echo '<p>&nbsp;</p>';
echo '<p>&nbsp;</p>';
}
else
?>
<div align=center>
<strong><? echo $type?></strong>
</div>

<?
echo '<p>&nbsp;</p>';
echo '<p>&nbsp;</p>';
{
$query = 'select * from Hotels '

."where type = '$type' limit $offset,$limit";
$result2 = mysql_query($query2);
while ($row=mysql_fetch_assoc($result2))
{
$ID = $row['ID'];
$name = $row['name'];
$hoteldescr = $row['hoteldescr'];
$location = $row['location'];
$town = $row['town'];
$url = "http://www.example.gr/nikos/bestour/";
$url2 = "http://www.example.gr/nikos/bestour/pictures/";
$querypicture = "select * from Gallery where HotelID = '$ID'";
$resultpicture = mysql_query($querypicture);

while ($rowpicture=mysql_fetch_assoc($resultpicture))
{
$picture = $rowpicture['picture'];
$descritpion = $rowpicture['descritpion'];

?>
<table width="73%" border="3" align="center" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF">
<tr bgcolor="#FFFFFF">
<td width="21%" rowspan="2" bordercolor="#FFFFFF" bgcolor="#0d9aef"><div align="center"><img src="<? echo $url2?><? echo $picture?>" alt="<? echo $descritpion?>" width="150" height="113"></div></td>
<td width="43%" height="45" bordercolor="#FFFFFF"><div align="center">Location: <? echo $location?> </div></td>
<td width="36%" bordercolor="#FFFFFF"><div align="center">Town: <? echo $town?></div></td>
</tr>
<tr>
<td height="78" colspan="2" bordercolor="#0d9aef"><div align="justify"><? echo $hoteldescr?></div></td>
</tr>
</table>
<?

}
}

//determine number of pages needed

$pages=intval($numrows/$limit);

//if number of records isn't evenly divisible by the number of pages above, add another page.

if ($numrows%$limit)

{
$pages++;
}

//set value of first record to be displayed
$first_record = $offset + 5;

echo "<br />";

//see if we're on the last page
if (!((($offset)/$limit)+1==$pages))

{
$last_record = $offset + $limit;
//is last page
echo " <strong>$last_record</strong> of <strong>$numrows</strong> $type(s). Click on image to view the $type <br />";
}

else

{
//is NOT last page - send this to browser

echo " <strong>$numrows</strong> of <strong>$numrows</strong> $type(s). Click on image to view the $type<br>";

}

echo "<br />\n";

//prepare and display links to other results in browser

if ($offset!= 0)

{

$prevoffset=$offset-$limit;

//create a previous link - if we're not on the first page

echo "<a class='nav' href='$PHP_SELF?offset=$prevoffset'>&lt;&lt;&nbsp;Prev</a> &nbsp; \n";

}

//construct that shows just prev-next or all page numbers

if ($showpages == Y)
{
if ( $pages!= 1 )

{
for ($i=1;$i<=$pages;$i++)
{
$newoffset=$limit*($i-1);

if ( ((($offset)/$limit)==($i-1)) )
{

echo "$i &nbsp; \n";

}

else

{

echo "<a class='nav' href='$PHP_SELF?offset=$newoffset'>$i</a> &nbsp; \n";

}

}

}

}

if (!((($offset)/$limit)+1==$pages) && $pages!=1)

{

$newoffset=$offset+$limit;

//create a next link - if we're not on the last page

echo ("<a class='nav' href='$PHP_SELF?offset=$newoffset'>Next&nbsp;&gt;&gt;</a><p>\n");

}

else

{
echo "No more $type(s) to display!";
}
}
}
?>

[edited by: jatar_k at 4:49 pm (utc) on July 8, 2005]
[edit reason] examplified url [/edit]

omoutop

1:48 pm on Jul 8, 2005 (gmt 0)

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



thx angelis...the problem with the line 1 error was solved by copying and pasting the whole code written in PHPEdit v.0.6 into a notepad...the thing is that PHPedit is full of bugs......and I get some weird problems some times..like the one today

however...my script still has a prob:

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /....../demo.php on line 56

2 of 2 hotel(s). Click on image to view the hotel
which is located in a query....it can be fixed....thx all of you for helping me....i ll try to work it out now and fix the whole thing.