Jump to content

Need help with error


boblang

Recommended Posts

I'm new to MySQL and PHP and currently working on a membership directory. I'm using GatorHost to host and test, They are currently using PHP 5.2.6 with safe mode turned off.

 

I'm creating a membership listing in a HTML table. using the following code:

 

<?php
// Connect to the members database
$dbh=mysql_connect ("localhost", "ldshome0_user",
"user") or die('Cannot connect to the PSEA Directory database because: ' . mysql_error);
mysql_select_db ("ldshome0_Mdirectory");

// Get the number of rows in the database
$num=mysql_numrows($result);
mysql_close();

?>

<body bgcolor="#000080">

<h2 style="text-align:center; margin-bottom:5px;">Perris Secondary Education Association</h2>
<h3 style="text-align:center; margin-top:5px";>Merbership Directory</h3>

<!-- banner -->
<div align="center">
<img border="0" src="images/schoolImages/community-header.jpg" width="700" height="125">
</div> 

<!-- Set up header for table -->
<div align="center">
<table id="table1" border="0" height="1" width="704">
    <tr style="background-color:#800000; color:#FFFFFF;font-weight:600;text-align:center;">
  <td>Last Name</td>
  <td>MI First</td>
  <td>Site</td>
  <td>Phone</td>
  <td>Email Address</td>
</tr>
<tr>
      
      <!--
      <td style="text-align:left;">
  <p style="text-align:center;"><strong><a name="alpha">A</a></strong></p>
  </td>
      <td>
      -->
      
      <?php
      // get the table data and display each member in a new row
      
      $increment=0;
        while ($i < $num)
        {
         $mem_id = mysql_result($result,$i,"member_id");
         $first  = mysql_result($result,$i,"firstName");
         $last   = mysql_result($result,$i,"lastName");
         $mi     = mysql_result($result,$i,"middleName");
         $Phone  = mysql_result($result,$i,"workPhone");
         $email  = mysql_result($result,$i,"emailAddress");
         
         echo "<td>$mem_id</td>
               <td>$first</td>
               <td>$last</tr>
               <td>$mi</td>
               <td>$Phone</td>
               <td>$email</td>
               </tr>";
          
        $i++;
        }
      ?>
    </tr>
</table>  
</div>
<!--#include virtual="includes/bottomMenu.txt"-->
<!--#include virtual="includes/footer.txt"-->

 

The error message I receive is:

"Parse error: syntax error, unexpected '}' in /home/boblan66/public_html/displayrows.php on line 98"

 

Although this seems simple enough, I checked and rechecked my code and reread my books to no avail. Can someone with a fresh pair of eyes please help.

 

Also, how do I show my code snippit as to not take up so much room?

 

Thanks...

 

Link to comment
https://forums.phpfreaks.com/topic/134246-need-help-with-error/
Share on other sites

If you want the code to appear in window, enclose it in [ code] [/ code] tags (but drop the space between '[' and 'code]'  and between '[/' and 'code]')

 

I don't think it is the line 98... See... the error message says, it encounters } where it didn't expect it to be. The most often cause for these errors is something simple, like forgetting to put ; at the end of the line, or having more closing braces } than opening ones { in the lines before the line, for which error is reported.

 

However, if error message says, that there's unexpected } in line 98, it means there is a } in line 98... and there is none in the code you posted. You might think it's line 98, because your editor might be giving you wrong numbers... What editor you're using BTW?

 

So. If you could post here several lines of code before line 98, and several lines after it, it would be helpful in tracking down this brace }

 

 

Link to comment
https://forums.phpfreaks.com/topic/134246-need-help-with-error/#findComment-698907
Share on other sites

I hope I'm not redoing this one, but I received a posting error and figured I needed to do this again.

 

I have modified the code to what is shown below, and the error messages no longer appera. However, the listing is not displayed when I run the code. Yes there's members inserted into the table.

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>PSEA Membership Directory Listing - as of 11-01-08</title>
  
  <link rev="made" href="mailto:[email protected]" />
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
  <meta name="generator" content="NoteTab Light 4.95" />
  <meta name="author" content="R.Langevin" />
    
  <link rel="stylesheet" type="text/css" href="stylesheet.css" media="all">
  <link rel="stylesheet" type="text/css" href="directory.css" media="all">
</head>

<?php

// Connect to the members database
$dbh=mysql_connect ("localhost", "ldshome0_user",
"user") or die('Cannot connect to the PSEA Directory database because: ' . mysql_error);
mysql_select_db ("ldshome0_Mdirectory");

// Get the number of rows in the table
$query="SELECT COUNT(*) FROM members WHERE member_id >= '1'";
$numrow=mysql_query($query);

?>

<body bgcolor="#000080">

<h2 style="text-align:center; margin-bottom:5px;">Perris Secondary Education Association</h2>
<h3 style="text-align:center; margin-top:5px";>Merbership Directory</h3>

<!-- banner -->
<div align="center">
<img border="0" src="images/schoolImages/community-header.jpg" width="700" height="125">
</div> 

<!-- Set up header for table -->
<div align="center">
<table id="table1" border="0" height="1" width="704">
    <tr style="background-color:#800000; color:#FFFFFF;font-weight:600;text-align:center;">
  <td>Last Name</td>
  <td>First</td>
  <td>m.i</td>
  <td>Phone</td>
  <td>Email Address</td>
</tr>
<tr>
      
<?php
      // get the table data and display each member in a new row
      
      $i=0;
        while ($i < $num)
        {
         $mem_id = mysql_result($result,$i,"member_id");
         $first  = mysql_result($result,$i,"firstName");
         $last   = mysql_result($result,$i,"lastName");
         $mi     = mysql_result($result,$i,"middleName");
         $Phone  = mysql_result($result,$i,"workPhone");
         $email  = mysql_result($result,$i,"emailAddress");
         
         echo "<td>$mem_id</td>
               <td>$first</td>
               <td>$last</tr>
               <td>$mi</td>
               <td>$Phone</td>
               <td>$email</td>
               </tr>";
          
        $i++;
        }
?>
    </tr>
</table>  
</div>
<!--#include virtual="includes/bottomMenu.txt"-->
<!--#include virtual="includes/footer.txt"-->

</body>
</html>

 

Also, there will be about a 1000 members inserted into this table. Is the GROUP BY the best thing to use for grouping by the first character of the last name?

 

 

Link to comment
https://forums.phpfreaks.com/topic/134246-need-help-with-error/#findComment-698992
Share on other sites

You're not retrieving user information from database anywhere.

 

The only query you use is SELECT COUNT(*) FROM members WHERE member_id >= '1' and it will only count how many users are there in members table...

 

You should lookup some tutorial on how to use mysql with PHP, because you're not doing it right at this moment (sorry for being so vague, but I'm a bit tired today, and it's getting late here). Also look up mysql in PHP manual. There are some examples there (and they're actually very good examples)

Link to comment
https://forums.phpfreaks.com/topic/134246-need-help-with-error/#findComment-699001
Share on other sites

mchl, Thanks you for your insight. I know about being tied. I work with serverly handicapped teens and I am a stroke victem myself. I love woring with computers and enjoying learning php. I'll look up the reference you provided. Thanks again.. :)

Link to comment
https://forums.phpfreaks.com/topic/134246-need-help-with-error/#findComment-699369
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.