Jump to content

Parse error, but not what it looks like...


PC Nerd

Recommended Posts

im receiving this error, which is usually shown when youve left out the ; or somethingbut i havent........ the ontly thing which could be wrong is probably the array value which im trying to echo, this is my error:


Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in URL\B_A-Base.php on line 62


my code......

[code]<?php #40

if(!$_COOKIE){
echo "Please login again.  <a href= 'B_A-Home.html'>log in again here</a>";
}

else{### Display normal page

require("inc_files/Database_link.inc");
$User_Name = $_COOKIE['User_Name'];
$General_Stats_SQL = "SELECT Points, Research, Sustainability, Attack, Defense, Friends, Units, Resource_1 FROM Table_1 WHERE User_Name = ".$User_Name;
$Query = mysql_Query($General_Stats_SQL, $DB_Server);
$Stats = mysql_fetch_array($Query);
$Stats['M_Power'] = $Stats['Attack'] + $Stats['Defense'] /2;




echo "<center>";
echo "<table border='1' width='100%' hight='75'>";
echo "<tr hight='200'>"; $60
echo "<td width='50%' hight='50'>";
echo "<p>POINTS: $Stats['Points']</p>";
echo "<p>RESEARCH COUNT: $Stats['Research']</p>";
echo "<p>SUSTAINABILITY: $Stats['Sustainability']</p>";
echo "<p>MILITARY POWER: $Stats[']</p>";

echo "<blockquote>";
echo "<p>ATTACK: $Stats['Attack']"</p>";
echo "<p>DEFENSE: $Stats['Defense']</p>";
echo "</blockquote>";
echo "<p>FRIENDS: $Stats['Friends']</p>";


echo "</td>";

echo "<td width='50%' hight='50'>";
echo "<h3>Preferances</h3>";

echo "</td>";

echo "</tr>";
echo "<tr hight='200>";

echo "<td width='50%' hight=50'>";
echo "<h3>RECENT RESEARCH</h3>";
echo "<img src="Graphics\TECHS.GIF" alt="Techs">";

echo "</td>";

echo "<td width='50%' hight='50'>";
echo "RECENT SITE DOVELOPMENTS";
echo "</td>";

echo "</tr>";
echo "</table>";
echo "</center>";



}
?>[/code]


does any one have any suggestions as to what could be cauaseing this
Link to comment
Share on other sites

See where the colors start to get funky?

[code]
echo "<p>ATTACK: $Stats['Attack']"</p>";
echo "<p>DEFENSE: $Stats['Defense']</p>";
echo "</blockquote>";
echo "<p>FRIENDS: $Stats['Friends']</p>";
[/code]

You put a " after $Stats['Attack'].
Link to comment
Share on other sites

Try

[CODE]
echo "<p>POINTS: ".$Stats['Points']."</p>";
echo "<p>RESEARCH COUNT: ".$Stats['Research']."</p>";
echo "<p>SUSTAINABILITY: ".$Stats['Sustainability']."</p>";
echo "<p>MILITARY POWER: ".$Stats['']</p>"; // an array index is missing in this line

echo "<blockquote>";
echo "<p>ATTACK: ".$Stats['Attack']."</p>";
echo "<p>DEFENSE: ".$Stats['Defense']."</p>";
echo "</blockquote>";
echo "<p>FRIENDS: ".$Stats['Friends']."</p>";
[/CODE]
Link to comment
Share on other sites

You need to read up on string syntax. Personally I prefer concatenation with single quotes, but there are many ways to assemble strings:

http://nl2.php.net/manual/en/language.types.string.php

I took out all parse errors, and most of them where string syntax errors.

[code]<?php
error_reporting(E_ALL);
#40

if(!$_COOKIE){
echo "Please login again.  <a href= 'B_A-Home.html'>log in again here</a>";
}

else{### Display normal page

require("inc_files/Database_link.inc");
$User_Name = $_COOKIE['User_Name'];
$General_Stats_SQL = "SELECT Points, Research, Sustainability, Attack, Defense, Friends, Units, Resource_1 FROM Table_1 WHERE User_Name = ".$User_Name;
$Query = mysql_Query($General_Stats_SQL, $DB_Server);
$Stats = mysql_fetch_array($Query);
$Stats['M_Power'] = $Stats['Attack'] + $Stats['Defense'] /2;




echo "<center>";
echo "<table border='1' width='100%' hight='75'>";
echo "<tr hight='200'>";
echo "<td width='50%' hight='50'>";
echo '<p>POINTS: '.$Stats['Points'].'</p>';
echo '<p>RESEARCH COUNT: '.$Stats['Research'].'</p>';
echo '<p>SUSTAINABILITY: '.$Stats['Sustainability'].'</p>';
echo '<p>MILITARY POWER: '.$Stats['SOME_ARRAY_INDEX!!!!!!!!!!!!!!!!!'].'</p>';

echo "<blockquote>";
echo '<p>ATTACK: '.$Stats['Attack'].'</p>';
echo '<p>DEFENSE: '.$Stats['Defense'].'</p>';
echo "</blockquote>";
echo '<p>FRIENDS: '.$Stats['Friends'].'</p>';


echo "</td>";

echo "<td width='50%' hight='50'>";
echo "<h3>Preferances</h3>";

echo "</td>";

echo "</tr>";
echo "<tr hight='200>";

echo "<td width='50%' hight=50'>";
echo "<h3>RECENT RESEARCH</h3>";
echo "<img src='Graphics\TECHS.GIF alt='Techs'>";

echo "</td>";

echo "<td width='50%' hight='50'>";
echo "RECENT SITE DOVELOPMENTS";
echo "</td>";

echo "</tr>";
echo "</table>";
echo "</center>";



}
?>[/code]
Link to comment
Share on other sites

ok...
ive added the array index, and the string formated accourding to jesirose
AND THERE IS STILL THIS ERROR :<  i dont understand about the {} in string formatting but i dont think it applies.

thanks for your help, but are there anymore suggestions?
Link to comment
Share on other sites

ok, the error:



Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in URL/B_A-Base.php on line 62


code:

[code]<html>

<head>
<link rel="stylesheet" type="text/css" href="B_A-CSS.css">
<title>Battle Ages Login</title>
</head>

<body>

<table>

<thead>
<td class = 'left'>
<img src="Graphics\Small_Logo.GIF" alt="Logo" width = '75%' hight = '75%' align = 'left'>
</td>

<td class = "centre">
</td>

<td class = 'right'> #20
<img src="Graphics\Small_Logo.GIF" alt="Logo" width = '75%' hight = '75%' align = 'right'>
</td>

</thead>

<tbody>

<tr hight="250">

<td width="20%">
</td>

<td width="60%" hight="75">
<b>
<center>
<h1>BASE</h1>
</center>
</b>

<?php #40

if(!$_COOKIE){
echo "Please login again.  <a href= 'B_A-Home.html'>log in again here</a>";
}

else{### Display normal page

require("inc_files/Database_link.inc");
$User_Name = $_COOKIE['User_Name'];
$General_Stats_SQL = "SELECT Points, Research, Sustainability, Attack, Defense, Friends, Units, Resource_1 FROM Table_1 WHERE User_Name = ".$User_Name;
$Query = mysql_Query($General_Stats_SQL, $DB_Server);
$Stats = mysql_fetch_array($Query);
$Stats['M_Power'] = $Stats['Attack'] + $Stats['Defense'] /2;




echo "<center>";
echo "<table border='1' width='100%' hight='75'>";
echo "<tr hight='200'>";
echo "<td width='50%' hight='50'>";
echo "<p>POINTS: .$Stats['Points']."</p>";
echo "<p>RESEARCH COUNT: ."$Stats['Research']."</p>";
echo "<p>SUSTAINABILITY: ."$Stats['Sustainability']."</p>";
echo "<p>MILITARY POWER: ."$Stats['M_Power']."</p>";

echo "<blockquote>";
echo "<p>ATTACK: ."$Stats['Attack']."</p>";
echo "<p>DEFENSE: ."$Stats['Defense']."</p>";
echo "</blockquote>";
echo "<p>FRIENDS: ."$Stats['Friends']."</p>";


echo "</td>";

echo "<td width='50%' hight='50'>";
echo "<h3>Preferances</h3>";

echo "</td>";

echo "</tr>";
echo "<tr hight='200>";

echo "<td width='50%' hight=50'>";
echo "<h3>RECENT RESEARCH</h3>";
echo "<img src="Graphics\TECHS.GIF" alt="Techs">";

echo "</td>";

echo "<td width='50%' hight='50'>";
echo "RECENT SITE DOVELOPMENTS";
echo "</td>";

echo "</tr>";
echo "</table>";
echo "</center>";



}
?>


</td>

<td width="20%">
</td>

</tr>
</tbody>
</table>

</body>

</hmtl>
[/code]


im completely stupped
Link to comment
Share on other sites

[quote author=PC Nerd link=topic=123315.msg509524#msg509524 date=1169355117]
dont understand about the {} in string formatting but i dont think it applies.
[/quote]

It does. But string concatenation works fine too.

Anyway:

[code]<?php
echo "<p>POINTS: ".$Stats['Points']."</p>";
echo "<p>RESEARCH COUNT: ".$Stats['Research']."</p>";
echo "<p>SUSTAINABILITY: ".$Stats['Sustainability']."</p>";
echo "<p>MILITARY POWER: ".$Stats['M_Power']."</p>";

echo "<blockquote>";
echo "<p>ATTACK: ".$Stats['Attack']."</p>";
echo "<p>DEFENSE: ".$Stats['Defense']."</p>";
echo "</blockquote>";
echo "<p>FRIENDS: ".$Stats['Friends']."</p>";
?>[/code]

Will fix it.
Link to comment
Share on other sites

Line 62 is
[code]<?php
echo "<p>POINTS: .$Stats['Points']."</p>";
?>[/code]
Notice that you don't have and ending double quote before the ".", add that and this error will go away:
[code]<?php
echo "<p>POINTS: ".$Stats['Points']."</p>";
?>[/code]

You've made this mistake on the following 3 lines also.

Ken
Link to comment
Share on other sites

[code=php:0]
require("inc_files/Database_link.inc");
[/code]

I do not recommend using a .inc as a php extention. Because if you entered www.domain.com/inc/example.inc all your code will be readable because your preprocessor does not parse "inc" or "include" files. Instead, try and use example.inc.php.

I made that mistake when I was a beginner, It wasn't pretty ;)
Link to comment
Share on other sites

ok, error fixed,

now im getting the error with this code:


[code]require("inc_files/Database_link.inc");
$User_Name = $_COOKIE['User_Name'];
$General_Stats_SQL = "SELECT Points, Research, Sustainability, Attack, Defense, Friends, Units, Resource_1 FROM Table_1 WHERE User_Name = ".$User_Name;
$Query = mysqli_query($DB_Server, $General_Stats_SQL);
$Stats = mysqli_fetch_array($Query);
$Stats['M_Power'] = $Stats['Attack'] + $Stats['Defense'] /2;[/code]

the line defining the mysqli_fetch_arry()......



ERROR:
Warning: mysqli_query() expects parameter 1 to be mysqli, string given in C:\xampp\xampp\xampp\htdocs\Battle-Ages\B_A-Base.php on line 51

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in C:\xampp\xampp\xampp\htdocs\Battle-Ages\B_A-Base.php on line 52


i thought i got it correct, i know the $DB_Server is correct, its the query thats not working.


thankyou for all your help.......
Link to comment
Share on other sites

[code=php:0]
require("inc_files/Database_link.inc");
$User_Name = $_COOKIE['User_Name'];
$General_Stats_SQL = "SELECT Points, Research, Sustainability, Attack, Defense, Friends, Units, Resource_1 FROM Table_1 WHERE User_Name = ".$User_Name;
$Query = mysqli_query($General_Stats_SQL, $DB_Server);
$Stats = mysqli_fetch_array($Query);
$Stats['M_Power'] = $Stats['Attack'] + $Stats['Defense'] /2;
[/code]

Switch them around.

For you SQL query, try this.

[sql]
SELECT Points, Research, Sustainability, Attack, Defense, Friends, Units, Resource_1 FROM Table_1 WHERE User_Name = '$User_Name'
[/sql]

Link to comment
Share on other sites

Whether they are surrounded by php tag's, or not doesn't matter.  They can pull up those .inc files into the browser, and get information out of them directly, not only is it a valid point, but it is one of the dumbest security mistakes you could make.

I use
whatever.inc.php
That way php still parses them, unless you custom setup your server to process .inc file's, and it's till not a good idea to get in the general habit, as it's well... Dumb.
Link to comment
Share on other sites

ok...... switched them around and got this error:

Warning: mysqli_query() expects parameter 1 to be mysqli, string given in C:\xampp\xampp\xampp\htdocs\Battle-Ages\B_A-Base.php on line 51

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in C:\xampp\xampp\xampp\htdocs\Battle-Ages\B_A-Base.php on line 52
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.