473,503 Members | 2,150 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

getting parse error

116 New Member
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
6 1463
Dormilich
8,658 Recognized Expert Moderator Expert
the opening brace of line #32 has not been closed.
Jun 10 '10 #2
angelicdevil
116 New Member
but why doesnt it display the message in 50 53 and 55 when the condition is correct
Jun 10 '10 #3
Dormilich
8,658 Recognized Expert Moderator Expert
those lines are syntactically correct.
Jun 10 '10 #4
JKing
1,206 Recognized Expert Top Contributor
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
angelicdevil
116 New Member
perfect it works thanx jking and dormilich
Jun 10 '10 #6
angelicdevil
116 New Member
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

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

Similar topics

2
16280
by: entoone | last post by:
I'm getting the following error Parse error: parse error, expecting `','' or `';'' in /home/notarywe/public_html/php/update2.php on line 108 Here is line 108 <input type="text" name="ud_first"...
10
590
by: Stuart Rogers | last post by:
I have just setup my website with a new linux hosting service. I have copied over my scripts and the jpgraph (the stable version) files from my working local lan linux server. The hosting service...
4
2664
by: Marcin Dobrucki | last post by:
I've been having some problems with a parse error that I can't figure out (PHP 4.3.11 on Solaris9). Sample code: <?php // getting strange parse errors on this class A { var $value; function...
6
1476
by: Jim Anderson | last post by:
I'm just starting to use XML and I'm thinking of using DocBook for some documentation. I tried my first simple example from the book and I'm getting a parse error. I iniitally typed in the...
2
3665
by: urmyfriend | last post by:
Hi, I am getting the parse error while i try to execute a simple sql query in postgres. java.sql.SQLException: ERROR: parser: parse error at or near "and" at character 58 The Query has...
2
1352
by: Sianaba | last post by:
I am getting help from a website to fix my malware etc problem.... i was instructed to run a Kaspersky scan and now when i try to get to my specific forum i get this come up instead: Parse error:...
2
1247
by: DavidPr | last post by:
I'm getting - parse error, unexpected T_LNUMBER - error messages referring to the last "if" lines of this code. What I'm trying to do is check the database and if this user's article row isn't...
2
3207
by: Lawrence Krubner | last post by:
Imagine a template system that works by getting a file, as a string, and then putting it through eval(), something like this: $formAsString = $controller->command("readFileAndReturnString",...
15
2074
by: micky125 | last post by:
Lo all, Ive been getting the error message Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/moneill/public_html/input.html...
45
6799
by: angelicdevil | last post by:
i have 2 tables 1 is status_type with field name status and other is users with field username and status now i want that the first listbox lists all status from status type ( this i have achieved...
0
7205
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7349
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7467
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5594
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5022
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3177
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3168
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
746
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.