By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,930 Members | 1,321 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,930 IT Pros & Developers. It's quick & easy.

getting parse error

100+
P: 116
i m trying to display a message based on code status against the code in the database for on the code entered.
however it gives me a parse error
Expand|Select|Wrap|Line Numbers
  1. <?php require_once("includes/functions.php"); ?>
  2. <?php
  3.  
  4. // Database Constants
  5. define("DB_SERVER", "localhost");
  6. define("DB_USER", "tara");
  7. define("DB_PASS", "tara");
  8. define("DB_NAME", "book");
  9.  
  10. ?>
  11.  
  12. <?php
  13.  
  14. // 1. Create a database connection
  15. $connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS);
  16. if (!$connection) {
  17.     die("Database connection failed: " . mysql_error());
  18. }
  19.  
  20. // 2. Select a database to use 
  21. $db_select = mysql_select_db(DB_NAME,$connection);
  22. if (!$db_select) {
  23.     die("Database selection failed: " . mysql_error());
  24. }
  25. ?>
  26.  
  27. <?php
  28.  
  29.     include_once("includes/form_functions.php");
  30.  
  31.     // START FORM PROCESSING
  32.     if (isset($_POST['submit'])) { // Form has been submitted.
  33.         $code = trim(mysql_prep($_POST['code']));
  34.         $count_code = 0;
  35.  
  36.          // checks database for the code for errors
  37.              $result_code = mysql_query("SELECT code FROM orders WHERE code = '{$code}' " );
  38.             confirm_query($result_code);
  39.             if (mysql_num_rows($result_code) == 1) 
  40.             {
  41.             $count_code = $count_code + 1;
  42.             }
  43.  
  44.         // checks database for the status for errors
  45.              $result_codestatus = mysql_query("SELECT codestatus FROM orders WHERE code = '{$code}'");    
  46.             confirm_query($result_codestatus);
  47.             if (mysql_num_rows($result_codestatus) == 1)
  48.             {    
  49.                 if ($result_codestatus=="P"){
  50.                 $message = " Your status is pending";   
  51.                 }
  52.                 if ($result_codestatus=="W"){
  53.                 $message = " Your status is waiting";                      }
  54.                 if ($result_codestatus=="A"){
  55.                 $message = " Your status is approved";
  56.                 }        
  57.  
  58.             }
  59.  
  60.             else 
  61.             {// Code does not existing
  62.             $code = "";
  63.             $message = " Your code doesn't exist";
  64.             }    
  65.  
  66. ?>
  67. <html>
  68.     <head>
  69.         <title>sitename</title>
  70.         <link href="stylesheets/public.css" media="all" rel="stylesheet" type="text/css" />
  71.     </head>
  72.     <body>
  73.         <div id="header">
  74.             <h1>sitename</h1>
  75.         </div>
  76.         <div id="main">
  77. <table id="structure">
  78.     <tr>
  79.         <td id="navigation">
  80.             <a href="welcome.php">Return to Menu</a><br />
  81.             <br />
  82.         </td>
  83.         <td id="page">
  84.             <h2>Login</h2>
  85.             <?php if (!empty($message)) {echo "<p class=\"message\">" . $message . "</p>";} ?>
  86.  
  87.             <?php $code = ""; ?>
  88.  
  89.             <form action="status.php" method="post">
  90.             <table>
  91.                 <tr>
  92.                     <td>Enter Code:</td>
  93.                     <td><input type="text" name="code" maxlength="40" value="<?php echo htmlentities($code); ?>" /></td>
  94.                 </tr>
  95.  
  96.                 <tr>
  97.                     <td colspan="2"><input type="submit" name="submit" value="Check" /></td>
  98.                 </tr>
  99.             </table>
  100.             </form>
  101.         </td>
  102.     </tr>
  103. </table>
  104.         </div>
  105.         <div id="footer">Copyright 2010</div>
  106.     </body>
  107. </html>
  108. <?php
  109.     // Close connection
  110.     mysql_close($connection);
  111. ?>    
  112.  
Jun 10 '10 #1
Share this Question
Share on Google+
6 Replies


Dormilich
Expert Mod 5K+
P: 8,639
the opening brace of line #32 has not been closed.
Jun 10 '10 #2

100+
P: 116
but why doesnt it display the message in 50 53 and 55 when the condition is correct
Jun 10 '10 #3

Dormilich
Expert Mod 5K+
P: 8,639
those lines are syntactically correct.
Jun 10 '10 #4

JKing
Expert 100+
P: 1,206
The function mysql_query returns a resource. You will need to use another function such as mysql_fetch_row or mysql_fetch_array to access the data. I altered your code so you should be able to copy and paste. Give it a try and let me know how it works out for you.

Expand|Select|Wrap|Line Numbers
  1. <?php require_once("includes/functions.php"); ?>
  2. <?php
  3.  
  4. // Database Constants
  5. define("DB_SERVER", "localhost");
  6. define("DB_USER", "tara");
  7. define("DB_PASS", "tara");
  8. define("DB_NAME", "book");
  9.  
  10. ?>
  11.  
  12. <?php
  13.  
  14. // 1. Create a database connection
  15. $connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS);
  16. if (!$connection) {
  17.     die("Database connection failed: " . mysql_error());
  18. }
  19.  
  20. // 2. Select a database to use 
  21. $db_select = mysql_select_db(DB_NAME,$connection);
  22. if (!$db_select) {
  23.     die("Database selection failed: " . mysql_error());
  24. }
  25. ?>
  26.  
  27. <?php
  28.  
  29.     include_once("includes/form_functions.php");
  30.  
  31.     // START FORM PROCESSING
  32.     if (isset($_POST['submit'])) { // Form has been submitted.
  33.         $code = trim(mysql_prep($_POST['code']));
  34.         $count_code = 0;
  35.  
  36.          // checks database for the code for errors
  37.              $result_code = mysql_query("SELECT code FROM orders WHERE code = '{$code}' " );
  38.             confirm_query($result_code);
  39.             if (mysql_num_rows($result_code) == 1) 
  40.             {
  41.             $count_code = $count_code + 1;
  42.             }
  43.  
  44.         // checks database for the status for errors
  45.              $result_codestatus = mysql_query("SELECT codestatus FROM orders WHERE code = '{$code}'");    
  46.             confirm_query($result_codestatus);
  47.             if (mysql_num_rows($result_codestatus) == 1)
  48.             {    
  49.                 $row_codestatus = mysql_fetch_row($result_codestatus);
  50.                 if ($row_codestatus[0]=="P"){
  51.                 $message = " Your status is pending";   
  52.                 }
  53.                 if ($row_codestatus[0]=="W"){
  54.                 $message = " Your status is waiting";                      }
  55.                 if ($row_codestatus[0]=="A"){
  56.                 $message = " Your status is approved";
  57.                 }        
  58.  
  59.             }
  60.  
  61.             else 
  62.             {// Code does not existing
  63.             $code = "";
  64.             $message = " Your code doesn't exist";
  65.             }    
  66.  
  67. ?>
  68. <html>
  69.     <head>
  70.         <title>sitename</title>
  71.         <link href="stylesheets/public.css" media="all" rel="stylesheet" type="text/css" />
  72.     </head>
  73.     <body>
  74.         <div id="header">
  75.             <h1>sitename</h1>
  76.         </div>
  77.         <div id="main">
  78. <table id="structure">
  79.     <tr>
  80.         <td id="navigation">
  81.             <a href="welcome.php">Return to Menu</a><br />
  82.             <br />
  83.         </td>
  84.         <td id="page">
  85.             <h2>Login</h2>
  86.             <?php if (!empty($message)) {echo "<p class=\"message\">" . $message . "</p>";} ?>
  87.  
  88.             <?php $code = ""; ?>
  89.  
  90.             <form action="status.php" method="post">
  91.             <table>
  92.                 <tr>
  93.                     <td>Enter Code:</td>
  94.                     <td><input type="text" name="code" maxlength="40" value="<?php echo htmlentities($code); ?>" /></td>
  95.                 </tr>
  96.  
  97.                 <tr>
  98.                     <td colspan="2"><input type="submit" name="submit" value="Check" /></td>
  99.                 </tr>
  100.             </table>
  101.             </form>
  102.         </td>
  103.     </tr>
  104. </table>
  105.         </div>
  106.         <div id="footer">Copyright 2010</div>
  107.     </body>
  108. </html>
  109. <?php
  110.     // Close connection
  111.     mysql_close($connection);
  112. ?>    
  113.  
  114.  
Jun 10 '10 #5

100+
P: 116
perfect it works thanx jking and dormilich
Jun 10 '10 #6

100+
P: 116
another thing ...if say at the time of displaying the message i dont want the text box to enter code to be displayed how can i hide it and disable it?
Jun 10 '10 #7

Post your reply

Sign in to post your reply or Sign up for a free account.