Author Topic: Whats wrong with my php script ?  (Read 1325 times)

0 Members and 1 Guest are viewing this topic.

pllaybuoy

  • Guest
Whats wrong with my php script ?
« on: 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
Code: [Select]

<?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
« Last Edit: October 17, 2012, 10:01:20 pm by ande »

Offline ande

  • Owner
  • Titan
  • *
  • Posts: 2664
  • Cookies: 256
    • View Profile
Re: Whats wrong with my php script ?
« Reply #1 on: October 17, 2012, 10:01:53 pm »
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.
« Last Edit: October 17, 2012, 10:02:40 pm by ande »
if($statement) { unless(!$statement) { // Very sure } }
https://evilzone.org/?hack=true

pllaybuoy

  • Guest
Re: Whats wrong with my php script ?
« Reply #2 on: October 17, 2012, 10:03:39 pm »
Thanks ,  I feel like a retard now  :-X

Offline Kulverstukas

  • Administrator
  • Zeus
  • *
  • Posts: 6627
  • Cookies: 542
  • Fascist dictator
    • View Profile
    • My blog
Re: Whats wrong with my php script ?
« Reply #3 on: October 17, 2012, 10:05:24 pm »
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.

pllaybuoy

  • Guest
Re: Whats wrong with my php script ?
« Reply #4 on: October 17, 2012, 10:09:56 pm »
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

Offline Simba

  • Serf
  • *
  • Posts: 47
  • Cookies: 1335
  • programisiai.lt
    • View Profile
    • Programisiai.lt
Re: Whats wrong with my php script ?
« Reply #5 on: October 17, 2012, 11:58:27 pm »
I suggest  you to use IDE, i recommend NetBeans . It will greatly speed up writing code and you will learn faster.
« Last Edit: October 23, 2012, 06:08:51 pm by Simba »

Offline Xires

  • Noob Eater
  • Administrator
  • Knight
  • *
  • Posts: 379
  • Cookies: 149
    • View Profile
    • Feed The Trolls - Xires
Re: Whats wrong with my php script ?
« Reply #6 on: October 23, 2012, 03:48:05 pm »
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.
-Xires

Offline Simba

  • Serf
  • *
  • Posts: 47
  • Cookies: 1335
  • programisiai.lt
    • View Profile
    • Programisiai.lt
Re: Whats wrong with my php script ?
« Reply #7 on: October 23, 2012, 06:08:40 pm »
Damn, Yeah Xires.
Thanks