4 Replies - 3025 Views - Last Post: 26 July 2012 - 05:08 AM Rate Topic: -----

#1 synlight  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 89
  • View blog
  • Posts: 582
  • Joined: 14-September 11

Unexpected $end, embedding checkbox in table

Posted 25 July 2012 - 09:23 AM

This is part of a project for school. The program was working well until I decided to put all of my output into a table (the only way I know to make it look nice, so far). I am getting an "unexpected $end on line 86" error. I did some research and saw that this usually means I am missing a closing tag, or a } somewhere, but I have combed through this code a few times and can't find it. Maybe I am embedding my checkbox wrong, and that will cause it? I know help may be limited without access to the other files and the database I am using, I just thought I would ask. Thanks for any help. The form feeding into this file works fine.

<pre>
<?php

//FILENAME : BB1.php
//PROGRAMMER : redacted
//PURPOSE : Process form and query database

          extract ($_POST);   //EXTRACT form
          
           if (empty($username))  //check for username
              printf("<h2>You did not enter a user name. Please press the BACK button.\n</h2>");
           else //connect to database
            {
                $link  =  mysql_connect ("localhost", "root", "password");  //Connect to the database
                if (!$link) die("Could not connect: ". mysql_error());
                
                if (!mysql_select_db ("cpt283db"))
                die("Problem with the database: " . mysql_error());
 


           if ($dept==1)
              $department = "Books";
           elseif ($dept ==2)
               $department = "Video";
           else
               $department = "Music";
               
           $query = "SELECT * FROM products WHERE department = '$department'";
           
           $result  = mysql_query($query);
           
           

            //begin heredoc
            print<<<ENDFIRST
<!doctype html public "-//W3C//DTD HTML 4.0 //EN"><html><head><title>BB's Online SUperstore</title></head>
<body bgcolor = "#388E8E">
<h3>$username, please select any $department you would like to know more about: </h3><br><br />
<form action = "BB2.php" method = "POST">
<font face = "verdana" color = "white">
<table cellspacing="2" cellpadding="2" id="tabid" border='1'>
<!-- Headers for the display of items -->
<thead>
<tr>
<th><strong>ITEM ID</strong></th>
<th><strong>AUTHOR/ARTIST</strong></th>
<th><strong>TITLE</strong></th>
<th><strong>MEDIA</strong></th>
<th><strong>FEATURE</strong></th>
</tr>
</thead>
ENDFIRST;
//end heredoc

           while  ($row = mysql_fetch_assoc($result))
           {
               
                $ID = $row['ID'];
                $name = $row['entertainerauthor'];
                $title = $row['title'];
                $media = $row['media'];
                $feature = $row['feature'];
               ?>

               <tr>
                    <td valign="top" align="left" ><input type = "checkbox" name = "choices[]" value = "title"/></td>
                    <td valign="top" align="left" ><?php echo $ID; ?></td>
                    <td valign="top" align="left" ><?php echo $name; ?></td>
					<td valign="top" align="left" ><?php echo $title;?></td>
                    <td valign="top" align="left" ><?php echo $media; ?></td
					<td valign="top" align="right"><?php echo $feature;?></td>
				</tr>
           }//END WHILE
    <br />
    <p /><input type = "submit" value = "SUBMIT"><input type = "reset" value = "CLEAR">
    </form></font></body></html>

<?PHP
     mysql_close ($link); //Close the db connection
}//END ELSE connection
?>
</pre>



Is This A Good Question/Topic? 0
  • +

Replies To: Unexpected $end, embedding checkbox in table

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6078
  • View blog
  • Posts: 23,546
  • Joined: 23-August 08

Re: Unexpected $end, embedding checkbox in table

Posted 25 July 2012 - 09:46 AM

Read the docs on heredoc syntax, and pay particular attention to the big red box labeled Warning.
Was This Post Helpful? 1
  • +
  • -

#3 synlight  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 89
  • View blog
  • Posts: 582
  • Joined: 14-September 11

Re: Unexpected $end, embedding checkbox in table

Posted 25 July 2012 - 10:00 AM

View PostJackOfAllTrades, on 25 July 2012 - 11:46 AM, said:

Read the docs on heredoc syntax, and pay particular attention to the big red box labeled Warning.


Thank you for the link.

The only rule I see that I didn't follow was indenting the identifier, although I was following the example the instructor had us use, and what's in my textbook. When I took out the table head, the heredoc works fine even though the opening identifier is indented.

Was that what you were directing me to? The rest of my heredoc follows the conventions listed from what I can see.
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6078
  • View blog
  • Posts: 23,546
  • Joined: 23-August 08

Re: Unexpected $end, embedding checkbox in table

Posted 25 July 2012 - 10:36 AM

Yep, that was it :)
Was This Post Helpful? 1
  • +
  • -

#5 synlight  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 89
  • View blog
  • Posts: 582
  • Joined: 14-September 11

Re: Unexpected $end, embedding checkbox in table

Posted 26 July 2012 - 05:08 AM

Thank you!! I have been trying since yesterday to fix this on my own, and it's still not working. Any help would be greatly appreciated, even my professor can't find what I'm doing wrong. I am going to provide 2 php files, and a screenshot of what is going wrong.

****EDIT***** I think I have narrowed the problem down to this line of code:

 <td valign="top" align="right"><input type = "checkbox" name = "choices[]" value = "<?PHP echo $ID; ?><?php echo $title;?></td>
(on line 71)

I am trying to embed a checkbox into my table for user selections.

Problem 1: I am still getting the "unexpected $end" error in the first php file. I can remove the table if I have to, it is not part of the assignment, but I would REALLY prefer to learn how to do this. Here is the code for that file:

<pre>
<?php

//FILENAME : BB1.php
//PROGRAMMER : Synlight
//PURPOSE : Process form and query database

          extract ($_POST);   //EXTRACT form
          
           if (empty($username))  //check for username
              printf("<h2>You did not enter a user name. Please press the BACK button.\n</h2>");
           else //connect to database
            {
                $link  =  mysql_connect ("localhost", "root", "password");  //Connect to the database
                if (!$link) die("Could not connect: ". mysql_error());
                
                if (!mysql_select_db ("cpt283db"))
                die("Problem with the database: " . mysql_error());
 


           if ($dept==1)
              $department = "Books";
           elseif ($dept ==2)
               $department = "Video";
           else
               $department = "Music";
               
           $query = "SELECT * FROM products WHERE department = '$department'";
           
           $result  = mysql_query($query);
           
           

            //begin heredoc
print<<<ENDFIRST
<!doctype html public "-//W3C//DTD HTML 4.0 //EN"><html><head></head>
<body bgcolor = "#388E8E">
<font face = "verdana" color = "white">
<form action = "BB2.php" method = "POST">
<h3>$username, please select any $department you would like to know more about: </h3><br><br />
<table cellspacing="2" cellpadding="2" id="tabid" border='1'>
<thead>
<tr>
<th><strong>CHOOSE</strong></th>
<th><strong>ITEM ID</strong></th>
<th><strong>AUTHOR/ARTIST</strong></th>
<th><strong>TITLE</strong></th>
<th><strong>MEDIA</strong></th>
<th><strong>FEATURE</strong></th>
<th><strong>SUMMARY</strong></th>
</tr>
</thead>
ENDFIRST;
//end heredoc

           while  ($row = mysql_fetch_assoc($result))
           {
               
                $ID = $row['ID'];
                $name = $row['entertainerauthor'];
                $title = $row['title'];
                $media = $row['media'];
                $feature = $row['feature'];

             ?>

	        <tbody>
         	<tr>
                    <td valign="top" align="right"><input type = "checkbox" name = "choices[]" value = "<?PHP print $ID; ?>"/><?PHP print $title."\n";?></td>
					<td valign="top" align="left" ><?php echo $ID; ?></td>
                    <td valign="top" align="left" ><?php echo $name; ?></td>
					<td valign="top" align="left" ><?php echo $title;?></td>
                    <td valign="top" align="left" ><?php echo $media; ?></td
					<td valign="top" align="right"><?php echo $feature;?></td>


            </tr>
           }
    <br />
    <p /><input type = "submit" value = "SUBMIT"><input type = "reset" value = "CLEAR">
    </form></font></body></html>

<?PHP
     mysql_close ($link); //Close the db connection
}//END ELSE connection
?>
</pre>




I have a html file that provides the initial form. If you need to see it, let me know. But the file works fine until I add the table. If I just do a series of checkboxes (adding the table head into the heredoc, and the table itself inside the while loop), is when the problem pops up.




Problem number 2: I am using a join to query 2 tables to get the result set. I have to display (in this order)
ID#
Entertainer/Author
Title,
Price,
UnitsInStock

The SQL query I am using works in my MySQL console, and returns the proper results in the proper order. But, when I render the table, the UnitsInStock are displaying above the table, the Summary is in the InStock cell, and the Summary cell is empty.

Posted Image

Here is the code for that php file:

<!doctype html public "-//W3C//DTD HTML 4.0 //EN">
<html>
<head>
       <title>BB's Online Superstore</title>
</head>
<body bgcolor = "#388E8E">
<font face = "verdana" color = "white">
<pre>
<?php
    //FILE : BB2php
     //PROG : Synlight
     //PURP : Process check boxes from BB1, return db info

      define ("ROOTPW", "password");
     extract ($_POST);

     if (!isset($choices))
     {
        printf ("No titles selected.\n");
        printf ("Please push your back button and choose at least one!\n");
     }
     else     //Process each checkbox choice
     {
        $link = mysql_connect("localhost", "root", ROOTPW);
        if (!$link) die("Could not connect: " . mysql_error());
 }
         if (!mysql_select_db ("cpt283db"))
           die("Problem with the database: " . mysql_error());
      ?>
        <h1>Here are your selections!</h1>
        
        <table cellspacing="2" cellpadding="2" id="tabid" border='1'>

	<!-- Headers for the display of items -->
	<thead>
	<tr>
		<th><strong>ITEM ID</strong></th>
        <th><strong>AUTHOR/ARTIST</strong></th>
		<th><strong>TITLE</strong></th>
		<th><strong>PRICE</strong></th>
		<th><strong>IN STOCK</strong></th>
        <th><strong>SUMMARY</strong></th>
	</tr>
	</thead>
	<tbody>
         <?php


        foreach ($choices as $value)
        {
           $query = "SELECT products.ID, products.entertainerauthor, products.title, prodInv.UnitPrice, prodInv.UnitsInStock,
                  products.summary FROM products INNER JOIN prodInv ON products.ID = prodinv.ID WHERE products.ID = '$value'";
           $result = mysql_query($query);

           if ($result)
           {
               $row = mysql_fetch_assoc($result);

                       $ID = $row['ID'];
                       $name = $row['entertainerauthor'];
                       $title = $row['title'];
                       $price = $row['UnitPrice'];
                       $stock = $row['UnitsInStock'];
                       $summary = $row['summary'];
                     ?>
                     
				<tr>

					<td valign="top" align="left" ><?php echo $ID; ?></td>
                    <td valign="top" align="left" ><?php echo $name; ?></td>
					<td valign="top" align="left" ><?php echo $title;?></td>
                    <td valign="top" align="left" ><?php echo $price; ?></td
					<td valign="top" align="right"><?php echo $stock;?></td>
					<td valign="top" align="right"><?php echo $summary;?></td>

				</tr>
					<?php
           }//ENDIF
           else printf ("Error with the DB result set!\n");
        }//END FOREACH

        mysql_close($link);

 ?>
</pre>
</font>
</body>
</html>


I know this is a ton of code, and I tried to explain things the best I could so no one has to waste any time. Any help would be appreciated.

This post has been edited by synlight: 26 July 2012 - 05:37 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1