Where's the error?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Wldrumstcs
Forum Commoner
Posts: 98
Joined: Wed Nov 26, 2003 8:41 pm

Where's the error?

Post by Wldrumstcs »

Okay, in the script below, there is an error saying that there is an unexpected $ at the very bottom of the page. Where is the error?

Code: Select all

<?php
}ELSEIF($_GET[a] != "logout" OR $_GET[a] != "verify" OR $_GET[a] != "post"){

mysql_connect("localhost","$username","$password") or die ("Unable to connect to MySQL server."); 
$db = mysql_select_db("$database") or die ("Unable to select requested database.");

$query="SELECT * FROM teachers ORDER BY id ASC";
$result=mysql_query($query);

$num=mysql_num_rows($result);

mysql_close();

$i=0;
while ($i < $num) {
$teachers=mysql_result($result,$i,"username");


$main = "<form method='POST' action='delete.php?a=verify'>
			<table border='0' width='100%' cellspacing='0' cellpadding='0' id='table10'>
				<tr>
					<td align='right' width='100%' colspan='2'>
					<p align='center'>$error</td>
				</tr>
				<tr>
					<td align='center' width='100%' colspan='2'>
					<b><font size='2'>*NOTE*:&nbsp; Don't abuse this power...</font></b></td>
				</tr>
<tr>
<td height='10'>
</td>
</tr>
				<tr>
					<td align='right' width='50%' valign='top'>
					<p align='right'><b>Your Name:</b></td>
					<td align='left' width='50%'>$_COOKIE[username]<br>
					<font size='2'>(To login under a different username, </font> <a href='http://www.*****.com/login.php?a=logout'>
					<font size='2'>click here.)</font></a></td>
				</tr>
				<tr>
					<td align='right' width='50%'><b>Teacher that will be deleted:</b></td>
					<td width='50%' align='left'>
                      <select name='filter_teachers'>
  <option value='showall'>Choose a Teacher</option>
  	<option>----------------------</option>
	
<option value='$teachers'>$teachers</option>
			
			$i++;
}
	
  </select>
  </td>
                    </tr>
                    <tr>
					<td align='right' width='50%'>&nbsp;</td>
					<td align='left' width='50%'>&nbsp;</td>
				</tr>
			</table>
			<p>
			<input type='submit' value='Proceed' name='submit' tabindex='3' style='font-weight: bold; border-style: dashed; border-width: 1px; background-color: #999999'></p>
						
		</form>";
		}


?>
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

what is the exact error?
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

is that the entire script?
Wldrumstcs
Forum Commoner
Posts: 98
Joined: Wed Nov 26, 2003 8:41 pm

Post by Wldrumstcs »

"Parse error: parse error, unexpected $ in /home/delete.php on line 353"
Line 353 is the very bottom of the page (I didn't include it). I know that the error is somewhere in this portion of the script, specifically the dropdown menu.
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

try changing
[phpwhile ($i < $num) {
$teachers=mysql_result($result,$i,"username");


$main = "<form method='POST' action='delete.php?a=verify'>
<table border='0' width='100%' cellspacing='0' cellpadding='0' id='table10'>
<tr>
<td align='right' width='100%' colspan='2'>
<p align='center'>$error</td>
</tr>
<tr>
<td align='center' width='100%' colspan='2'>
<b><font size='2'>*NOTE*:&nbsp; Don't abuse this power...</font></b></td>
</tr>
<tr>
<td height='10'>
</td>
</tr>
<tr>
<td align='right' width='50%' valign='top'>
<p align='right'><b>Your Name:</b></td>
<td align='left' width='50%'>$_COOKIE[username]<br>
<font size='2'>(To login under a different username, </font> <a href='http://www.*****.com/login.php?a=logout'>
<font size='2'>click here.)</font></a></td>
</tr>
<tr>
<td align='right' width='50%'><b>Teacher that will be deleted:</b></td>
<td width='50%' align='left'>
<select name='filter_teachers'>
<option value='showall'>Choose a Teacher</option>
<option>----------------------</option>

<option value='$teachers'>$teachers</option>

$i++;
}

</select>
</td>
</tr>
<tr>
<td align='right' width='50%'>&nbsp;</td>
<td align='left' width='50%'>&nbsp;</td>
</tr>
</table>
<p>
<input type='submit' value='Proceed' name='submit' tabindex='3' style='font-weight: bold; border-style: dashed; border-width: 1px; background-color: #999999'></p>

</form>";
}

to:

Code: Select all

while ($i < $num) {
$teachers=mysql_result($result,$i,"username");


$main = "<form method='POST' action='delete.php?a=verify'>
            <table border='0' width='100%' cellspacing='0' cellpadding='0' id='table10'>
                <tr>
                    <td align='right' width='100%' colspan='2'>
                    <p align='center'>$error</td>
                </tr>
                <tr>
                    <td align='center' width='100%' colspan='2'>
                    <b><font size='2'>*NOTE*:&nbsp; Don't abuse this power...</font></b></td>
                </tr>
<tr>
<td height='10'>
</td>
</tr>
                <tr>
                    <td align='right' width='50%' valign='top'>
                    <p align='right'><b>Your Name:</b></td>
                    <td align='left' width='50%'>$_COOKIE[username]<br>
                    <font size='2'>(To login under a different username, </font> <a href='http://www.*****.com/login.php?a=logout'>
                    <font size='2'>click here.)</font></a></td>
                </tr>
                <tr>
                    <td align='right' width='50%'><b>Teacher that will be deleted:</b></td>
                    <td width='50%' align='left'>
                      <select name='filter_teachers'>
  <option value='showall'>Choose a Teacher</option>
      <option>----------------------</option>

<option value='$teachers'>$teachers</option>

  </select>
  </td>
                    </tr>
                    <tr>
                    <td align='right' width='50%'>&nbsp;</td>
                    <td align='left' width='50%'>&nbsp;</td>
                </tr>
            </table>
            <p>
            <input type='submit' value='Proceed' name='submit' tabindex='3' style='font-weight: bold; border-style: dashed; border-width: 1px; background-color: #999999'></p>

        </form>";
            $i++;

        }
Wldrumstcs
Forum Commoner
Posts: 98
Joined: Wed Nov 26, 2003 8:41 pm

Post by Wldrumstcs »

kinda worked. the page displays, but it doesnt output all the names in the DB, only the first one. that has to do with the placement of i++
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

usually this is caused byforgetting to close a bracket {}

count how many brackets you have, it should be an even number
Wldrumstcs
Forum Commoner
Posts: 98
Joined: Wed Nov 26, 2003 8:41 pm

Post by Wldrumstcs »

the brackets are all there. there is no error tho, just a lack of loading info from a DB.
Wldrumstcs
Forum Commoner
Posts: 98
Joined: Wed Nov 26, 2003 8:41 pm

Post by Wldrumstcs »

Here is what I have now (this is NOT solved). There is still a problem with loading all of the entries from the DB. This only outputs the first entry:

Code: Select all

}
ELSEIF($_GET[a] != "logout" OR $_GET[a] != "verify" OR $_GET[a] != "post"){


mysql_connect("localhost","$username","$password") or die ("Unable to connect to MySQL server."); 
$db = mysql_select_db("$database") or die ("Unable to select requested database.");

$query="SELECT * FROM teachers ORDER BY id DESC";
$result=mysql_query($query);

$num=mysql_num_rows($result);

mysql_close();

$i=0;
while ($i < $num) {
$teachers=mysql_result($result,$i,"username");



$main = "<form method='POST' action='delete.php?a=verify'>
			<table border='0' width='100%' cellspacing='0' cellpadding='0' id='table10'>
				<tr>
					<td align='right' width='100%' colspan='2'>
					<p align='center'>$error</td>
				</tr>
				<tr>
					<td align='center' width='100%' colspan='2'>
					<b><font size='2'>*NOTE*:&nbsp; Don't abuse this power...</font></b></td>
				</tr>
<tr>
<td height='10'>
</td>
</tr>
				<tr>
					<td align='right' width='50%' valign='top'>
					<p align='right'><b>Your Name:</b></td>
					<td align='left' width='50%'>$_COOKIE[username]<br>
					<font size='2'>(To login under a different username, </font> <a href='http://www.***.com/login.php?a=logout'>
					<font size='2'>click here.)</font></a></td>
				</tr>
				<tr>
					<td align='right' width='50%'><b>Teacher that will be deleted:</b></td>
					<td width='50%' align='left'>
                      <select name='filter_teachers'>
  <option value='showall'>Choose a Teacher</option>
  	<option>----------------------</option>
	
<option value='$teachers'>$teachers</option>


	
  </select>
  </td>
                    </tr>
                    <tr>
					<td align='right' width='50%'>&nbsp;</td>
					<td align='left' width='50%'>&nbsp;</td>
				</tr>
			</table>
			<p>
			<input type='submit' value='Proceed' name='submit' tabindex='3' style='font-weight: bold; border-style: dashed; border-width: 1px; background-color: #999999'></p>
						
		</form>";
			$i++;
			
}
npeelman
Forum Commoner
Posts: 32
Joined: Tue Jul 27, 2004 5:13 am
Location: Oviedo,FL.

Post by npeelman »

Wldrumstcs wrote:the brackets are all there. there is no error tho, just a lack of loading info from a DB.
Try changing:

$main = >>>EOV
<form method='POST' action='delete.php?a=verify'>
<table border='0' width='100%' cellspacing='0' cellpadding='0' id='table10'>
<tr>
<td align='right' width='100%' colspan='2'>
<p align='center'>$error</td>
</tr>
<tr>
<td align='center' width='100%' colspan='2'>
<b><font size='2'>*NOTE*:&nbsp; Don't abuse this power...</font></b></td>
</tr>
<tr>
<td height='10'>
</td>
</tr>
<tr>
<td align='right' width='50%' valign='top'>
<p align='right'><b>Your Name:</b></td>
<td align='left' width='50%'>$_COOKIE[username]<br>
<font size='2'>(To login under a different username, </font> <a href='http://www.*****.com/login.php?a=logout'>
<font size='2'>click here.)</font></a></td>
</tr>
<tr>
<td align='right' width='50%'><b>Teacher that will be deleted:</b></td>
<td width='50%' align='left'>
<select name='filter_teachers'>
<option value='showall'>Choose a Teacher</option>
<option>----------------------</option>

<option value='$teachers'>$teachers</option>

</select>
</td>
</tr>
<tr>
<td align='right' width='50%'>&nbsp;</td>
<td align='left' width='50%'>&nbsp;</td>
</tr>
</table>
<p>
<input type='submit' value='Proceed' name='submit' tabindex='3' style='font-weight: bold; border-style: dashed; border-width: 1px; background-color: #999999'></p>

</form>"
EOV;
$i++;
}
Wldrumstcs
Forum Commoner
Posts: 98
Joined: Wed Nov 26, 2003 8:41 pm

Post by Wldrumstcs »

nope. wtf is "eov"???
npeelman
Forum Commoner
Posts: 32
Joined: Tue Jul 27, 2004 5:13 am
Location: Oviedo,FL.

Post by npeelman »

Wldrumstcs wrote:nope. wtf is "eov"???
It's called HEREDOC... It's a delimeter method. Think of it as a third set of quotes. EOV can be whatever you want, just as long as they match. For me, EOV = End Of Variable.

Norm
Post Reply