943,691 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 451
  • PHP RSS
Jun 27th, 2009
0

Syntax Error

Expand Post »
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.

php Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dev_plant is offline Offline
1 posts
since Jun 2009
Jun 27th, 2009
0

Re: Syntax Error

The problem you are having is with your double quotes.
php Syntax (Toggle Plain Text)
  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:
php Syntax (Toggle Plain Text)
  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.
Reputation Points: 20
Solved Threads: 13
Junior Poster in Training
humbug is offline Offline
93 posts
since Oct 2005
Jun 28th, 2009
0

Re: Syntax Error

It was really buggy but I think I found all the bugs. Below is the corrected code.
php Syntax (Toggle Plain Text)
  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>
Sponsor
Featured Poster
Reputation Points: 410
Solved Threads: 258
Occupation: Genius
cwarn23 is offline Offline
3,004 posts
since Sep 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: php-mysql-javascript image gallery?
Next Thread in PHP Forum Timeline: protecting entire directory with php http authentication





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC