/    Sign up×
Community /Pin to ProfileBookmark

where clause

Hi I’m trying to add a where clause to the below query, for some reason it not working when a town is selected

I’m getting a sql error
here is there error

SQL Error: SELECT event_date FROM calendar_events WHERE event_community = South Porcupine GROUP BY event_date ORDER BY event_date

[code=php]
<form name=”changeCommunity” method=”post” action=”<?php echo
$PHP_SELF; ?>”>
<select name=”ChangeCommunity” onchange=”this.form.submit()”>
<option value=”Cochrane”>Cochrane</option>
<option value=”Timmins”>Timmins</option>
<option value=”South Porcupine”>South Porcupine</option>
<option value=”Kapuskasing”>Kapuskasing</option>
<option value=”Smooth Rock Falls”>Smooth Rock Falls</option>
<option value=”Iroquois Falls”>Iroquois Falls</option>
<option value=”Other”>Other</option>
</select>
</form>
<?php
$community = $_POST[‘ChangeCommunity’];
if(isset($_POST[‘ChangeCommunity’])){
$where = “WHERE event_community = $community”;
}else{

}

$sql = “SELECT event_date FROM calendar_events $where GROUP BY event_date ORDER BY event_date”;
$qry = mysql_query($sql) or die(“SQL Error: $sql<br” . mysql_error());
[/code]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@benifactorMar 03.2007 — try this...

[code=php]
<form name="changeCommunity" method="post" action="<?php echo

$PHP_SELF; ?>">
<select name="ChangeCommunity" onchange="this.form.submit()">
<option value="Cochrane">Cochrane</option>
<option value="Timmins">Timmins</option>
<option value="South Porcupine">South Porcupine</option>
<option value="Kapuskasing">Kapuskasing</option>
<option value="Smooth Rock Falls">Smooth Rock Falls</option>
<option value="Iroquois Falls">Iroquois Falls</option>
<option value="Other">Other</option>
</select>
</form>
<?php
if (isset($_POST['ChangeCommunity'])) {
mysql_query("select event_date FROM calender_events WHERE event_community = '$_POST[ChangeCommunity]' ORDER BY event_date") or die(mysql_error());
}
?>
[/code]
×

Success!

Help @kproc 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 6.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

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