Syntax Error

Reply

Join Date: Jun 2009
Posts: 1
Reputation: dev_plant is an unknown quantity at this point 
Solved Threads: 0
dev_plant dev_plant is offline Offline
Newbie Poster

Syntax Error

 
0
  #1
Jun 27th, 2009
I'm taking a course in Web development, learning to write PHP and I been working very hard on trying to find the errors in this script. I'm very new to programming and I get confused on where '," belong in the code.

Any suggestions you can give is very helpful. Thanks in advance.

  1. <?php
  2. /*Display this page
  3.  $places = 700;
  4. ?>
  5. <html>
  6. <head><title>Fix this script</title>
  7.  <style type='text/css'>
  8.   <!--
  9.   table {
  10.   margin-left: 3em;
  11.   padding: 5;
  12.   }
  13.   td {
  14.   padding: .1in .25in .1in .25in;
  15.   }
  16.  
  17.   h2,h3 {
  18.   font-weight: bold;
  19.   text-align: center;
  20.   }
  21.   -->
  22.  </style>
  23. </head>
  24. <body>
  25. <?php
  26. $event = "Three Hundredth Annual World Magic Convention" ;
  27. $schedule = array("Spells" => 1,"Potions" => 2,"Charms" => 3 );
  28. define("DATE","January 15");
  29.  
  30. echo "<h2>"style="color: red Announcing the $event"</h2>";
  31. echo "<h3>".DATE."</h3>";
  32. echo "<p>This yearly conference—the premier education and networking forum for the magic community—is the place";
  33. echo "to learn about the most successful magic methodologies and to understand how to integrate new magic technologies into your current practices. </p>";
  34.  
  35. echo '<p>This year's conference offers the following educational events.</p>';
  36.  
  37. echo "<table border='1'>"
  38.   <tr><th>Time</th><th>Session</td></tr>";
  39. foreach($schedule as $name => $time)
  40. {
  41.   echo "<tr>
  42.   <td>$time</td>
  43. <td>$name</td>
  44. </tr>";
  45. }
  46. echo "</table>;
  47. echo "<p style='margin-top: 2em'>Witches and Warlocks! Hurry and sign up! Places are filling up fast. ";
  48. echo '<h3>Only $places places left</h3>';
  49.  
  50.  
  51. ?>
  52. </body>
  53. </html>
  54.  
Last edited by peter_budo; Jun 28th, 2009 at 5:27 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 93
Reputation: humbug is an unknown quantity at this point 
Solved Threads: 13
humbug's Avatar
humbug humbug is offline Offline
Junior Poster in Training

Re: Syntax Error

 
0
  #2
Jun 27th, 2009
The problem you are having is with your double quotes.
  1. echo "value of the constant CONSTANT: " . CONSTANT;
notice the text in blue, this is a string. You are trying to put double quotes inside a string without escaping them. If you place a backslash directly before a double quote php will take it as a part of the string instead of the string termination:
  1. //like this:
  2. echo "value of the constant \"CONSTANT\": " . CONSTANT;
  3. //not this:
  4. echo "value of the constant "CONSTANT": " . CONSTANT;

Also, I don't think it is possible to put a string over multiple lines how you are. You should put them on one line and use '\n' (no quotes) to echo a new-line character.
"If your not having fun, your doing something wrong." - Humbug
★ Did I help you out? Did I piss you off? Add to my reputation!
The Gabriel Method is a great book for losing weight and keeping healthy - I know Jon Gabriel Personally.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,493
Reputation: cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about 
Solved Threads: 136
cwarn23's Avatar
cwarn23 cwarn23 is online now Online
Nearly a Posting Virtuoso

Re: Syntax Error

 
0
  #3
Jun 28th, 2009
It was really buggy but I think I found all the bugs. Below is the corrected code.
  1. <?php
  2. //Display this page
  3. $places = 700;
  4. ?>
  5. <html>
  6. <head><title>Fix this script</title>
  7. <style type='text/css'>
  8. <!--
  9. table {
  10. margin-left: 3em;
  11. padding: 5;
  12. }
  13. td {
  14. padding: .1in .25in .1in .25in;
  15. }
  16.  
  17. h2,h3 {
  18. font-weight: bold;
  19. text-align: center;
  20. }
  21. -->
  22. </style>
  23. </head>
  24. <body>
  25. <?php
  26. $event = 'Three Hundredth Annual World Magic Convention' ;
  27. $schedule = array('Spells' => 1,'Potions' => 2,'Charms' => 3 );
  28. define('DATE','January 15');
  29.  
  30. echo "<h2>\"style=\"color: red Announcing the $event\"</h2>";
  31. echo '<h3>'.DATE.'</h3>';
  32. echo '<p>This yearly conference—the premier education and networking forum for the magic community—is the place';
  33. echo 'to learn about the most successful magic methodologies and to understand how to integrate new magic technologies into your current practices. </p>';
  34.  
  35. echo '<p>This year\'s conference offers the following educational events.</p>';
  36.  
  37. echo '<table border="1">
  38. <tr><th>Time</th><th>Session</td></tr>';
  39. foreach($schedule as $name => $time)
  40. {
  41. echo "<tr>
  42. <td>$time</td>
  43. <td>$name</td>
  44. </tr>";
  45. }
  46. echo '</table>';
  47. echo '<p style=\'margin-top: 2em\'>Witches and Warlocks! Hurry and sign up! Places are filling up fast. ';
  48. echo '<h3>Only $places places left</h3>';
  49. ?>
  50. </body>
  51. </html>
Try not to bump 10 year old threads as it can be really annoying.
http://syntax.cwarn23.net/
Smilies: ^_* +_+ v_v -_- *~*`
My favourite PC. - MacGyver Fan
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC