getting parse error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • angelicdevil
    New Member
    • Apr 2009
    • 116

    getting parse error

    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
    Code:
    <?php require_once("includes/functions.php"); ?>
    <?php
    
    // Database Constants
    define("DB_SERVER", "localhost");
    define("DB_USER", "tara");
    define("DB_PASS", "tara");
    define("DB_NAME", "book");
    
    ?>
    
    <?php
    
    // 1. Create a database connection
    $connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS);
    if (!$connection) {
    	die("Database connection failed: " . mysql_error());
    }
    
    // 2. Select a database to use 
    $db_select = mysql_select_db(DB_NAME,$connection);
    if (!$db_select) {
    	die("Database selection failed: " . mysql_error());
    }
    ?>
    
    <?php
    	
    	include_once("includes/form_functions.php");
    	
    	// START FORM PROCESSING
    	if (isset($_POST['submit'])) { // Form has been submitted.
    		$code = trim(mysql_prep($_POST['code']));
    		$count_code = 0;
    		 			
     		// checks database for the code for errors
     			$result_code = mysql_query("SELECT code FROM orders WHERE code = '{$code}' " );
    			confirm_query($result_code);
    			if (mysql_num_rows($result_code) == 1) 
    			{
    			$count_code = $count_code + 1;
    			}
    			
    		// checks database for the status for errors
             	$result_codestatus = mysql_query("SELECT codestatus FROM orders WHERE code = '{$code}'");	
    			confirm_query($result_codestatus);
    			if (mysql_num_rows($result_codestatus) == 1)
    			{	
    			    if ($result_codestatus=="P"){
    			    $message = " Your status is pending";   
    			    }
    			    if ($result_codestatus=="W"){
    			    $message = " Your status is waiting";                      }
    			    if ($result_codestatus=="A"){
    			    $message = " Your status is approved";
    			    }		
    			
    			}
    			
    			else 
    			{// Code does not existing
    			$code = "";
    			$message = " Your code doesn't exist";
    			}	
    	
    ?>
    <html>
    	<head>
    		<title>sitename</title>
    		<link href="stylesheets/public.css" media="all" rel="stylesheet" type="text/css" />
    	</head>
    	<body>
    		<div id="header">
    			<h1>sitename</h1>
    		</div>
    		<div id="main">
    <table id="structure">
    	<tr>
    		<td id="navigation">
    			<a href="welcome.php">Return to Menu</a><br />
    			<br />
    		</td>
    		<td id="page">
    			<h2>Login</h2>
    			<?php if (!empty($message)) {echo "<p class=\"message\">" . $message . "</p>";} ?>
    			
    			<?php $code = ""; ?>
    			
    			<form action="status.php" method="post">
    			<table>
    				<tr>
    					<td>Enter Code:</td>
    					<td><input type="text" name="code" maxlength="40" value="<?php echo htmlentities($code); ?>" /></td>
    				</tr>
    							
    				<tr>
    					<td colspan="2"><input type="submit" name="submit" value="Check" /></td>
    				</tr>
    			</table>
    			</form>
    		</td>
    	</tr>
    </table>
    		</div>
    		<div id="footer">Copyright 2010</div>
    	</body>
    </html>
    <?php
    	// Close connection
    	mysql_close($connection);
    ?>
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    the opening brace of line #32 has not been closed.

    Comment

    • angelicdevil
      New Member
      • Apr 2009
      • 116

      #3
      but why doesnt it display the message in 50 53 and 55 when the condition is correct

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        those lines are syntactically correct.

        Comment

        • JKing
          Recognized Expert Top Contributor
          • Jun 2007
          • 1206

          #5
          The function mysql_query returns a resource. You will need to use another function such as mysql_fetch_row or mysql_fetch_arr ay 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.

          Code:
          <?php require_once("includes/functions.php"); ?>
          <?php
           
          // Database Constants
          define("DB_SERVER", "localhost");
          define("DB_USER", "tara");
          define("DB_PASS", "tara");
          define("DB_NAME", "book");
           
          ?>
           
          <?php
           
          // 1. Create a database connection
          $connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS);
          if (!$connection) {
              die("Database connection failed: " . mysql_error());
          }
           
          // 2. Select a database to use 
          $db_select = mysql_select_db(DB_NAME,$connection);
          if (!$db_select) {
              die("Database selection failed: " . mysql_error());
          }
          ?>
           
          <?php
           
              include_once("includes/form_functions.php");
           
              // START FORM PROCESSING
              if (isset($_POST['submit'])) { // Form has been submitted.
                  $code = trim(mysql_prep($_POST['code']));
                  $count_code = 0;
           
                   // checks database for the code for errors
                       $result_code = mysql_query("SELECT code FROM orders WHERE code = '{$code}' " );
                      confirm_query($result_code);
                      if (mysql_num_rows($result_code) == 1) 
                      {
                      $count_code = $count_code + 1;
                      }
           
                  // checks database for the status for errors
                       $result_codestatus = mysql_query("SELECT codestatus FROM orders WHERE code = '{$code}'");    
                      confirm_query($result_codestatus);
                      if (mysql_num_rows($result_codestatus) == 1)
                      {    
                          $row_codestatus = mysql_fetch_row($result_codestatus);
                          if ($row_codestatus[0]=="P"){
                          $message = " Your status is pending";   
                          }
                          if ($row_codestatus[0]=="W"){
                          $message = " Your status is waiting";                      }
                          if ($row_codestatus[0]=="A"){
                          $message = " Your status is approved";
                          }        
           
                      }
           
                      else 
                      {// Code does not existing
                      $code = "";
                      $message = " Your code doesn't exist";
                      }    
           
          ?>
          <html>
              <head>
                  <title>sitename</title>
                  <link href="stylesheets/public.css" media="all" rel="stylesheet" type="text/css" />
              </head>
              <body>
                  <div id="header">
                      <h1>sitename</h1>
                  </div>
                  <div id="main">
          <table id="structure">
              <tr>
                  <td id="navigation">
                      <a href="welcome.php">Return to Menu</a><br />
                      <br />
                  </td>
                  <td id="page">
                      <h2>Login</h2>
                      <?php if (!empty($message)) {echo "<p class=\"message\">" . $message . "</p>";} ?>
           
                      <?php $code = ""; ?>
           
                      <form action="status.php" method="post">
                      <table>
                          <tr>
                              <td>Enter Code:</td>
                              <td><input type="text" name="code" maxlength="40" value="<?php echo htmlentities($code); ?>" /></td>
                          </tr>
           
                          <tr>
                              <td colspan="2"><input type="submit" name="submit" value="Check" /></td>
                          </tr>
                      </table>
                      </form>
                  </td>
              </tr>
          </table>
                  </div>
                  <div id="footer">Copyright 2010</div>
              </body>
          </html>
          <?php
              // Close connection
              mysql_close($connection);
          ?>

          Comment

          • angelicdevil
            New Member
            • Apr 2009
            • 116

            #6
            perfect it works thanx jking and dormilich

            Comment

            • angelicdevil
              New Member
              • Apr 2009
              • 116

              #7
              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?

              Comment

              Working...