Click to See Complete Forum and Search --> : Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING ln 20


R.Noon
09-12-2005, 02:45 PM
Alright, the error is the title,
I could use some help with this page.

As always, Thanks in advance.
<?php
include('header.php');
$sql= "SELECT * FROM `post`";
$results=mysql_query($sql);
?>
<?php
if (!isset($_POST['subj']))
{?>
<form name="form1">
<select name="subj" onChange="MM_jumpMenu('parent',this,0)">
<option value="view_anouce.php">Site Updates</option>
<option value="view_anouce.php">Tech Support</option>
<option value="view_anouce.php">Web Design</option>
<option value="view_anouce.php">All</option>
</select>
</form>
<?php }
if (isset($_POST['subj']))
{ $viewSub = $_POST['subj'];
$posted = "SELECT * FROM `post` WHERE $viewSub == $row['subject']) || (viewSub == All"; }
//---------------------//
if (isset($viewSub))
{
if($username!=NULL){ ?><br><div align="left"><b><a href="addannouncement.php">Add An Announcement</a></b></div><br><? }?>
<table border="3">
<tr>
<?php if($username!=NULL){ ?><td align="center"><b>Options</b></td> <?php }?>
<td align="center"><b>Date</b></td>
<td align="center"><b>Anoucement</b></td>
<td align="center"><b>Posted By</b></td>
</tr>
<?php while($row=mysql_fetch_array($results))
{?>
<tr>
<?php if($username!=NULL){ ?><td><?php include('adminedit.php'); ?></td> <?php }?>
<td><?php echo date("d/m/y", $row{'date'}); ?></td>
<td valign="top"><?php echo $posted ?></td>
<td align="center" valign="middle"><?php echo $row{'username'}; ?></td>
</tr>"
<?php
}//echo $row{'post'};
?>
</table>
<?php include('footer.php'); ?>

NogDog
09-12-2005, 03:11 PM
This line has me confused in more than one way:

$posted = "SELECT * FROM `post` WHERE $viewSub == $row['subject']) || (viewSub == All"; }

Where do you get $row['subject']? I don't see it being set anywhere before this. In any case, it needs to be quoted within the query, assuming it's not a numeric field. Also, it's best to surround array element variables like that with braces "{}" when used in a quoted string literal to make sure PHP recognizes the complete variable expression.

What's with the parens around the ) || (? You have a closing paren with no opening one, followed by an opening paren with no closing one.

Should the final column in the WHERE clause be $viewSub instead of viewSub?

Lastly, "==" is not a valid operator in MySQL, you want to use "=" instead.

Assuming $row['subject'] is acutally set somewhere, I'd write that line as:

$posted = "SELECT * FROM `post` WHERE `$viewSub` = '{$row['subject']}' || `$viewSub` = 'All'"; }

(Well, actually, I'd use "OR" instead of "||", but that's just a style preference.)

R.Noon
09-12-2005, 06:59 PM
The $row['subject'] part so far for me has always referenced a specific row in the mysql database, which naturally in this case; is called subject.

SpectreReturns
09-12-2005, 08:53 PM
Wrong. mysql_query returns a resource id, which you then need to use some other functions to extract the data, which you'd then set to $row.

NogDog
09-12-2005, 09:41 PM
After your $result = mysql_query(); you'll need a $row = mysql_fetch_assoc($result); in order to get a result row (or use mysql_fetch_array() or mysql_fetch_row(), depending on how you want to work with it).