Jump to content

Parse error: syntax error, unexpected '{' in C:\xampp\htdocs\bench2\index2.php o


Recommended Posts

Can someone help with this?

 

 

<?php
//initialize session
session_start();
?>
<html>
<head>
<basefont face="Arial">
</head>
<body>

<?php


// set server access variables
$host = "localhost";
$user = "root";
$pass = "";
$db = "wercbench";


// open connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");

// select database
mysql_select_db($db) or die ("Unable to select database!");

// create query
$year_query = "SELECT distinct year FROM userdata";
$industry_query = "SELECT distinct comp_desc FROM comp_desc";
$metric_query = "SELECT metric_desc.met_desc, userdata.median, userdata.best_pract FROM metric_desc, userdata where metric_desc.met_key=userdata.met_key and $useryear=userdata.year";


// execute query
$year_result = mysql_query($year_query) or die ("Error in query: $query. ".mysql_error());
$industry_result = mysql_query($industry_query) or die ("Error in query: $query. ".mysql_error());
// see if any rows were returned
if (mysql_num_rows($year_result) > 0 or mysql_num_rows($industry_result)){
     // yes
     // print them one after another
if (!isset($_POST['wercbench1'])) {
 /*echo"<form method=\"POST\" action=\"<?php$_SERVER['PHP_SELF']; ?>\" name=\"wercbench1\">";*/
 echo"<form method=\"POST\" action=\"". $_SERVER['PHP_SELF']. "\" name=\"wercbench1\">";
     echo"<table style=\"width: 100%;\" border=\"1\" cellpadding=\"2\" cellspacing=\"2\">";
     echo"<tbody>";
     echo" <tr>";
     echo"   <td>Select the comparison year and group then click next";
     echo"   </td>";
     echo"   <td></td>";
     echo" </tr>";
     echo" <tr>";
     echo"  <td>";
     echo"   <select name=\"year\">";
     while($row = mysql_fetch_row($year_result)) {
     echo"<option value=\"" .$row[0]. "\">".$row[0]."</option>";
 }
     echo"   </select>";
     echo"   </td>";
     echo"   <td></td>";
     echo" </tr>";


     echo" <tr>";
     echo"   <td>";
 echo"   <select name=\"industry\">";
  while($row = mysql_fetch_row($industry_result)) {
     echo"<option value=\"" .$row[0]. "\">".$row[0]."</option>";
}
     echo"   </select>";
 echo"</td>";
     echo"   <td></td>";
     echo" </tr>";
     echo" <tr>";
     echo"   <td><input type=\"Submit\" value=\"Next\" name=\"wercbench1_next\"></button></td>";
     echo"   <td></td>";
     echo" </tr>";

    echo"</tbody>";
  echo"</table>";
echo"</form>";
}
}
elseif(!isset($_POST['wercbench2']) and (mysql_num_rows($metric_result) > 0){
    // yes
    // print them one after another
echo "<form action=\"<?php echo $_SERVER['PHP_SELF']; ?>\" method=\"post\" name\"wercbench2\">";
    echo "<table cellpadding=10 border=1>";
    echo "<tr>";
        echo "<td>Metric Description</td>";
        echo "<td>Average</td>";
        echo "<td>Best Practice</td>";
	echo "<td>Enter your value here</td>";
        echo "</tr>";
    while($row = mysql_fetch_row($metric_result)) {
        echo "<tr>";
        echo "<td>".$row[0]."</td>";
        echo "<td>" . $row[1]."</td>";
        echo "<td>".$row[2]."</td>";
	echo "<td><input type=\"text\" name=\"myvalue[]\" value=\"\" /></td>";
        echo "</tr>";
    }
    echo "<tr><td colspan=\"3\"> </td><td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Compare\"></td></tr></table>";
}
else {
    // no
    // print status message
    echo "No rows found!";
} 

// free result set memory
mysql_free_result($metric_result);
}
else {
    // no
    // print status message
    echo "No rows found!";
}
// free result set memory
mysql_free_result($year_result);
mysql_free_result($industry_result);

// close connection
mysql_close($connection);

?>

</body>
</html>

else {

    // no

    // print status message

    echo "No rows found!";

}

 

// free result set memory

mysql_free_result($metric_result);

}

 

thats extra^

 

 

 

 

 

  echo "</tr>";

    }

    echo "<tr><td colspan=\"3\"> </td><td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Compare\"></td></tr></table>";

}

 

^extra also.

 

i may be wrong, but im counting your open and closes..

I prefer to place opening and closing braces on separate lines, eg:

if(bla)
{
    if(blah bla)
    {
         more codee
    }

   code here
}

That will make sure code more readable, cleaner and easier to match braces.

 

Some editors have built in brace matching, which means when you're in a code block (code between { and }) it'll highlight the matching braces for that code block. I'm sure Notepad++ has this feature.

Guys, I am sorry but I still am getting:

 

 

Parse error: syntax error, unexpected '{' in C:\xampp\htdocs\bench2\index2.php on line 82

 

I have counted all my openings and closings and am just not seeing the issue

 

<?php
//initialize session
session_start();
?>
<html>
<head>
<basefont face="Arial">
</head>
<body>

<?php


// set server access variables
$host = "localhost";
$user = "root";
$pass = "";
$db = "wercbench";


// open connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");

// select database
mysql_select_db($db) or die ("Unable to select database!");

// create query
$year_query = "SELECT distinct year FROM userdata";
$industry_query = "SELECT distinct comp_desc FROM comp_desc";
$metric_query = "SELECT metric_desc.met_desc, userdata.median, userdata.best_pract FROM metric_desc, userdata where metric_desc.met_key=userdata.met_key and $useryear=userdata.year";


// execute query
$year_result = mysql_query($year_query) or die ("Error in query: $query. ".mysql_error());
$industry_result = mysql_query($industry_query) or die ("Error in query: $query. ".mysql_error());
// see if any rows were returned
if (mysql_num_rows($year_result) > 0 or mysql_num_rows($industry_result)){
     // yes
     // print them one after another
if (!isset($_POST['wercbench1'])) {
 /*echo"<form method=\"POST\" action=\"<?php$_SERVER['PHP_SELF']; ?>\" name=\"wercbench1\">";*/
 echo"<form method=\"POST\" action=\"". $_SERVER['PHP_SELF']. "\" name=\"wercbench1\">";
     echo"<table style=\"width: 100%;\" border=\"1\" cellpadding=\"2\" cellspacing=\"2\">";
     echo"<tbody>";
     echo" <tr>";
     echo"   <td>Select the comparison year and group then click next";
     echo"   </td>";
     echo"   <td></td>";
     echo" </tr>";
     echo" <tr>";
     echo"  <td>";
     echo"   <select name=\"year\">";
     while($row = mysql_fetch_row($year_result)) {
     echo"<option value=\"" .$row[0]. "\">".$row[0]."</option>";
 }
     echo"   </select>";
     echo"   </td>";
     echo"   <td></td>";
     echo" </tr>";


     echo" <tr>";
     echo"   <td>";
 echo"   <select name=\"industry\">";
  while($row = mysql_fetch_row($industry_result)) {
     echo"<option value=\"" .$row[0]. "\">".$row[0]."</option>";
}
     echo"   </select>";
 echo"</td>";
     echo"   <td></td>";
     echo" </tr>";
     echo" <tr>";
     echo"   <td><input type=\"Submit\" value=\"Next\" name=\"wercbench1_next\"></button></td>";
     echo"   <td></td>";
     echo" </tr>";

    echo"</tbody>";
  echo"</table>";
echo"</form>";
}
}
elseif(!isset($_POST['wercbench2']) and (mysql_num_rows($metric_result) > 0){
    // yes
    // print them one after another
echo "<form action=\"<?php echo $_SERVER['PHP_SELF']; ?>\" method=\"post\" name\"wercbench2\">";
    echo "<table cellpadding=10 border=1>";
    echo "<tr>";
        echo "<td>Metric Description</td>";
        echo "<td>Average</td>";
        echo "<td>Best Practice</td>";
	echo "<td>Enter your value here</td>";
        echo "</tr>";
    while($row = mysql_fetch_row($metric_result)) {
        echo "<tr>";
        echo "<td>".$row[0]."</td>";
        echo "<td>" . $row[1]."</td>";
        echo "<td>".$row[2]."</td>";
	echo "<td><input type=\"text\" name=\"myvalue[]\" value=\"\" /></td>";
        echo "</tr>";
    }
    echo "<tr><td colspan=\"3\"> </td><td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Compare\"></td></tr></table>";
}
else {
    // no
    // print status message
    echo "No rows found!";
}
// free result set memory
mysql_free_result($year_result);
mysql_free_result($industry_result);
mysql_free_result($metric_result);

// close connection
mysql_close($connection);

?>

</body>
</html>

elseif(!isset($_POST['wercbench2']) and (mysql_num_rows($metric_result) > 0){

should be

 

elseif(!isset($_POST['wercbench2']) and (mysql_num_rows($metric_result) > 0)){

 

You forgot to close the elseif

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.