Jump to content

Recommended Posts

Hi,

 

I'm a little bit new to php and I'm working on a script to display upcoming events.

 

Here's the script I have :

 

<?php 


require_once('../admin/config.php');

$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
	die('Failed to connect to server: ' . mysql_error());
}

$db = mysql_select_db(DB_DATABASE);
if(!$db) {
	die("Unable to select database");
}


$date = Date("Y-m-d");
$data = mysql_query("SELECT * FROM events WHERE event_date > $date ORDER by event_date") 
or die(mysql_error());

while($info = mysql_fetch_array( $data ))

			{					
?>
							<div class="indent-bottom17 border-bottom p8">
								<?php echo $date; ?>
								<h3 class="p4-1"><?php echo $info['event_city'].", ".$info['event_state']; ?></h3>
								<h6 class="p4-1">Course title : <?php echo $info['event_title']; ?></h6>
								   <a href="view_event.php?cmd=view&id=<?php echo $info['event_id']; ?>">View details...</a>
							</div>
<?php
			}
?>

 

I don't get any errors and the script seems to work except for the part that it also displays events from the past...it ignores the condition : SELECT * FROM events WHERE event_date > $date ORDER by event_date

 

I don't know if i'm doing this right but if anyone can point me to a solutions it would be really appreciated...Thanks!!

Literal dates in a query are strings and need to be enclosed by single-quotes WHERE event_date > '$date'

 

Without the single-quotes, a date looks like a math subtraction problem: WHERE event_date > 2012-08-08 evaluates to WHERE event_date > 1996

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.