Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parse error: syntax error, unexpected $end in test.php on line 237 2

Status
Not open for further replies.

evil1966

MIS
Dec 2, 2013
57
US
I need help finding the error. I have this code working to return data from a table.

Code:
   <?php 
   
 
	$username="me";
	$host="localhost";
	$password="********";
	$database="mydatabase";

	$con = mysql_connect($host,$username,$password);
    if(!$con)
    {
	 die("Unable to select database");
    }
    mysql_select_db($database,$con);
		
	$sql = "SELECT * FROM donors WHERE lastname LIKE '%$letter' ORDER BY lastname, firstname";
	
    $result = mysql_query($sql);

  ?>
  
   <h1>Donor List</h1>
   <p style="margin-left:25px;"> Click on any letter button or a column header to sort this list</p>
   <script> document.write(btns);</script>

  <table class="example table-autosort table-autofilter table-autopage:10 table-stripeclass:alternate    table-page-number:t1page table-page-count:t1pages table-filtered-rowcount:t1filtercount table-rowcount:t1allcount" id="t1">
  <thead>
    <tr>
        <th class="table-sortable:default" title="Click to sort">Greeting</th>
        <th class="table-sortable:default" title="Click to sort">First Name</th>
        <th class="table-sortable:default" title="Click to sort">Last Name</th>
        <th class="table-sortable:default" title="Click to sort">Company</th>
        <th class="table-sortable:default" title="Click to sort">Job Title</th>
        <th class="table-sortable:default" title="Click to sort">EMail</th>
        <th class="table-sortable:default" title="Click to sort">Business Phone</th>
        <th class="table-sortable:default" title="Click to sort">Home Phone</th>
        <th class="table-sortable:default" title="Click to sort">Cell Phone</th>
        <th class="table-sortable:default" title="Click to sort">Fax</th>
        <th class="table-sortable:default" title="Click to sort">Address</th>
        <th class="table-sortable:default" title="Click to sort">Address2</th>
        <th class="table-sortable:default" title="Click to sort">City</th>
        <th class="table-sortable:default" title="Click to sort">State</th>
        <th class="table-sortable:default" title="Click to sort">Zip</th>
    </tr>
  </thead>
 <tbody>

 <?php 
    
    while($row = mysql_fetch_array($result))
  {  
  
 ?>
       
 <tr>
     <td><?php echo $row['greeting']?></td>
     <td><?php echo $row['firstname']?></td>
     <td><?php echo $row['lastname']?></td>
     <td><?php echo $row['company']?></td>
     <td><?php echo $row['jobtitle']?></td>
     <td><?php echo $row['eMail']?></td>
     <td><?php echo $row['businessphone']?></td>
     <td><?php echo $row['homephone']?></td>
     <td><?php echo $row['cellphone']?></td>
     <td><?php echo $row['fax']?></td>
     <td><?php echo $row['address1']?></td>
     <td><?php echo $row['address2']?></td>
     <td><?php echo $row['city']?></td>
     <td><?php echo $row['state']?></td>
     <td><?php echo $row['zip']?></td>
  </tr>
  <?php 
  }
  mysql_close($con);
  ?> 
  
  
  
 </tbody>
 <tfoot>
    
    <tr>
        <td colspan="2" style="cursor:pointer;" class="table-page:previous">&lt; &lt; Previous</td>
        <td colspan="4" style="text-align:center;" colspan="1">Page <span id="t1page">1</span>&nbsp;of <span id="t1pages">11</span></td>
        <td colspan="2" style="cursor:pointer;" class="table-page:next">Next &gt; &gt;</td>
    </tr>
    <tr>
        <td colspan="8"><span id="t1filtercount">105</span>&nbsp;of <span id="t1allcount">105</span>&nbsp;rows match filter(s)</td>
    </tr></tfoot>
 </table>

I added script to add buttons for sorting the data.

Code:
<script>
var btns = "";
var letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var letterArray = letters.split("");
for(var i = 0; i < 26; i++){
    var letter = letterArray.shift();
    btns += '<button class="mybtns" onclick="alphabetSearch(\''+letter+'\');">'+letter+'</button>';
}
function alphabetSearch(let){}
</script>

That works, but the code to return the sorted data based on the button click throws the error.

Code:
  <?php 
   
[b][COLOR=#CC0000]   $results = "";
   $letter = "";
   if(isset($_GET['letter']) && strlen($_GET['letter']) == 1){
    $letter = preg_replace('#[^a-z]#i', '', $_GET['letter']);
    if(strlen($letter) != 1){
        echo "ERROR: Hack Attempt, after filtration the variable is empty.";
        exit();
    }[/color][/b]
    
	$username="me;
	$host="localhost";
	$password="*********";
	$database="mydatabase";

	$con = mysql_connect($host,$username,$password);
    if(!$con)
    {
	 die("Unable to select database");
    }
    mysql_select_db($database,$con);
		
	$sql = "SELECT * FROM donors WHERE lastname LIKE '%$letter' ORDER BY lastname, firstname";
	
    $result = mysql_query($sql);

  ?>

Thanks for the help.
 
Great explanation, Vacunita. Thank you very much. If I did this work all the time it would be one thing, but at best I tend to work on web coding once a year or two. I like this stuff, so even if it gets a little frustrating I want to it well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top