PC Nerd Posted January 21, 2007 Share Posted January 21, 2007 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 62my 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 Quote Link to comment Share on other sites More sharing options...
fert Posted January 21, 2007 Share Posted January 21, 2007 [code]echo "<tr hight='200'>"; $60[/code]should be[code]echo "<tr hight='200'>";[/code] Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 21, 2007 Share Posted January 21, 2007 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']. Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted January 21, 2007 Author Share Posted January 21, 2007 thats meant to be #60.............. a comment for the page line, by anyway, getting rid of it still cauase the error on line 62 Quote Link to comment Share on other sites More sharing options...
kobmat Posted January 21, 2007 Share Posted January 21, 2007 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 lineecho "<blockquote>";echo "<p>ATTACK: ".$Stats['Attack']."</p>";echo "<p>DEFENSE: ".$Stats['Defense']."</p>";echo "</blockquote>";echo "<p>FRIENDS: ".$Stats['Friends']."</p>";[/CODE] Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted January 21, 2007 Author Share Posted January 21, 2007 still the error..... thanks anyway anymore suggestions Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 21, 2007 Share Posted January 21, 2007 You still get the exact same error? Are you sure... you have the right file? Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted January 21, 2007 Author Share Posted January 21, 2007 100% sure its the right file...... Quote Link to comment Share on other sites More sharing options...
Destruction Posted January 21, 2007 Share Posted January 21, 2007 echo "<p>MILITARY POWER: $Stats[']</p>";notice there's no key for $stats[] just a single ' - try correcting that and the one that jesirose put up and try againDest Quote Link to comment Share on other sites More sharing options...
448191 Posted January 21, 2007 Share Posted January 21, 2007 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.phpI 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] Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted January 21, 2007 Author Share Posted January 21, 2007 ok...ive added the array index, and the string formated accourding to jesiroseAND 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? Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 21, 2007 Share Posted January 21, 2007 You changed it to exactly what he posted? Can you show us the error, perhaps it's a new line farther on now. Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted January 21, 2007 Author Share Posted January 21, 2007 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 62code:[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 Quote Link to comment Share on other sites More sharing options...
448191 Posted January 21, 2007 Share Posted January 21, 2007 [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]<?phpecho "<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. Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted January 21, 2007 Share Posted January 21, 2007 Is that specific page you keep postingB_A-Base.phpand not putting out an error on a page that is included in it, or something? Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 21, 2007 Share Posted January 21, 2007 You never fixed the one I posted!echo "<p>POINTS: .$Stats['Points']."</p>";Needs to beecho "<p>POINTS: ".$Stats['Points']."</p>"; Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted January 21, 2007 Share Posted January 21, 2007 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 Quote Link to comment Share on other sites More sharing options...
Eugene Posted January 21, 2007 Share Posted January 21, 2007 [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 ;) Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted January 21, 2007 Author Share Posted January 21, 2007 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 51Warning: 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 52i thought i got it correct, i know the $DB_Server is correct, its the query thats not working.thankyou for all your help....... Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted January 21, 2007 Author Share Posted January 21, 2007 in reply to the comement about require();, its ok, the inc files are souronded by <?php and ?> tags. but it helps be remember which are the included files, and chich are the php scriptsthanks anyway, very valid point Quote Link to comment Share on other sites More sharing options...
Eugene Posted January 21, 2007 Share Posted January 21, 2007 [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] Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted January 21, 2007 Share Posted January 21, 2007 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 usewhatever.inc.phpThat 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. Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted January 21, 2007 Author Share Posted January 21, 2007 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 51Warning: 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 Quote Link to comment Share on other sites More sharing options...
Eugene Posted January 21, 2007 Share Posted January 21, 2007 Nevermind, I was just reading mysqli page on php.net as I'm not very familiar with it. Revert back to [code=php:0]$Query = mysqli_query($DB_Server, $General_Stats_SQL);[/code] Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted January 21, 2007 Author Share Posted January 21, 2007 ok, errors at present:Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\xampp\xampp\htdocs\Battle-Ages\B_A-Base.php on line 52thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.