/    Sign up×
Community /Pin to ProfileBookmark

Error in MYSQL syntax?

Apparentely I have an error in my MYSQL syntax…
I know the problem is with my $query variable, but I’m not sure how to fix it.

TIA

error code — SQL error: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ‘Design.’ at line 1

[code=php]
<?php
include(‘header.php’);
$sql= “SELECT * FROM `post`”;
$results=mysql_query($sql);
$row=@mysql_fetch_array($results)
?>
<?php
if (!isset($_POST[‘subj’]))
{?>

<form method=”post”>
<dl align=”center”>~!~ Subject Of Announcement ~!~
<dd>Web Design<input type=”radio” name=”subj” value=”Web Design”></dd>
<dd>Tech Support<input type=”radio” name=”subj” value=”Tech Support”></dd>
<dd>Site Updates<input type=”radio” name=”subj” value=”Site Updates”></dd>
<dd>All<input type=”radio” name=”subj” value=”All”></dd>
</dl>
<input type=”submit” value=”View”>
</form>
<?php }
if (isset($_POST[‘subj’]))
{ $viewSub = $_POST[‘subj’];
if ($viewSub != “All”)
{
$query = “SELECT * FROM `post` WHERE `subject`=.$viewSub.”;
$result2 = mysql_query($query) or die(“SQL error: ” . mysql_error());
while($row2 = mysql_fetch_array($result2)){$posted = $row2[0]; }
}
else $posted = $row[‘post’];
}
//———————//
if (isset($viewSub))
{
if($username!=NULL){ ?><br><div align=”left”><b><a href=”addannouncement.php”>Add An Announcement</a><br> <? echo “You are Viewing “, $viewSub ,” announcements!”;?></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 if ($viewSub = “All”) {echo $row[‘post’];}
else {echo $posted;} ?></td>
<td align=”center” valign=”middle”><?php echo $row{‘username’}; ?></td>
</tr>
<?php
}
?>
</table>
<?php } ?>
<?php include(‘footer.php’); ?>
[/code]

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@chrysSep 28.2005 — Can you please do this, and then paste the output:

Change your mysql_query statements to the following:

mysql_query( $query ) or die( "ERROR!<br>" . mysql_error() . "<br>$query" );

Make sure the $query variable is the same in both the query statement and die statement. This will help us debug. Thanks ?
Copy linkTweet thisAlerts:
@NogDogSep 28.2005 — Should it be...
[code=php]
$query = "SELECT * FROM post WHERE subject='$viewSub'";
[/code]

...?
×

Success!

Help @R_Noon spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.3,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...