EvilZone
Programming and Scripting => Web Oriented Coding => : pllaybuoy October 17, 2012, 09:56:17 PM
-
I started learning php yesterday , have previous experience of c++
now tell me whats wrong with this script ?
I have installed WAMP and made a file whatever.php in www root directory
now every .php file there runs but this whatever.php gives error
heres the script
<?php
$display_prices = true;
if ($display_prices) {
echo "<table border=\”1\”>\n";
echo "<tr><td colspan=\"3\">";
echo "today’s prices in dollars";
echo "</td></tr>";
echo "<tr><td>\$14.00</td><td>\$32.00</td><td>\$71.00</td></tr>\n";
echo "</table>";
function addfucker($num1,$num2){echo $num1+$num2;}
$a=2;$b=3;
addfucker($a,$b);
function maketable($a,$b,$c,$d){
echo "<table><tr><td>$a</td><td>$b</td><td>$c</td><td>$d</td></tr></table>";
}
maketable("yo",3,"lo","5");
?>
on accessing it with mozilla (localhost:8888/whatever.php)it displays some orange table thingy saying "parse error, syntax error, unexpected end of file in c:/wamp/www/whatever.php on line 23"
Now the line 23 is ?>
what could be wrong with this line? :/
its a freaking end tag of php whats wrong with it
and I tried adding the html tags in this document like
this
<!Doctype html>
<head></head>
<body>
<?php
//above mentioned script
?>
</body>
</html>
And now it says the same error in line 29 which is </html>
wtf is wrong with this shit =s
-
You are missing an end curly bracket at the if($display_prices). So, the PHP engine goes through your code looking for it, but it cant fint it, once it reaches the bottom it will say the error is there because its the last line and there is no curly bracket there.
-
Thanks , I feel like a retard now :-X
-
I don't think you have a closing curly bracket for the IF statement on line 3.
Close the IF statement and it should work.
edit: ande was quicker, damn it.
-
I don't think you have a closing curly bracket for the IF statement on line 3.
Close the IF statement and it should work.
edit: ande was quicker, damn it.
Yes lol , he answered it in like minutes after I asked ,thanks though
-
I suggest you to use IDE, i recommend NetBeans . It will greatly speed up writing code and you will learn faster.
-
Simba; Perhaps you mean NetBeans?
There are loads of IDEs out there and no doubt they would help to some degree. However, there are a few things to keep in mind, whether using an IDE or not, that will help you out with issues like this.
- Keep your code organized and appropriately indented.
Doing this will help you to spot errors faster and make it easier to determine fixes.
- ALWAYS use braces for things like if-else trees, loops, explicit blocks, try-catch blocks, etc.
It may seem stupid to follow this rule for everything but if you get used to doing it, you'll save yourself quite a bit of time and effort finding and fixing bugs.
- Keep track of your variable names and their spelling.
Most people try to use short variables for one reason or another and this may involve weird abbreviations that aren't easily evident when reviewing the code. There's a lot of potential for misspellings when this happens and misspellings can happen in different ways. Using more descriptive variables and ensuring that they are spelled correctly(remember that many editors, not just IDEs, include spell checking support) can help eliminate many small & annoying syntax errors.
- Keep track of variable scope.
Lots of people keep track of variable scope by adopting a variable naming policy that involves including the scope for the variable name. Often global/module-level variables will begin with a 'g' or 'm'. Private class member variables may often begin with a 'c' or 'p'. Temporary use variables for loops or special blocks may often begin with 't'. Adopting a policy like this usually helps keep track of variable scope which in turn eliminates many conflicts and decreases the amount of time necessary to track down where & how a variable was declared.
-
Damn, Yeah Xires.
Thanks