Forum Moderators: coopster

Message Too Old, No Replies

Update column with CURDATE()

Table fails to update

         

mvaz

1:05 am on May 6, 2009 (gmt 0)

10+ Year Member



Hello, I have a table with 4 coumns:
`quote_id` tinyint(4) NOT NULL auto_increment,
`quote` text NOT NULL,
`author` varchar(255) NOT NULL,
`publish_date` date NOT NULL.

What I am trying to do is, check if there is today's date set in the publish_date field, if there is none, pull out one row at random, and update it's publish_date field to current date.

I tried to get this working by updating the field manually thru phpmyadmin, and then the 1st bit works, but then, it fails to update any fields when all records have publish_date as '0000-00-00' which is default to a date column.

Please review my below code and let me know where I have gone wrong. I have spent hours trying to get this working; it's 2am and my eyes are heavy I cannot do any more on this today. Please, please let me know your opinions and corrections on the code below.

<?php
$result = mysql_query("SELECT * FROM quotes WHERE publish_date=CURDATE()");
if($result) {
$sql = mysql_fetch_array($result);
echo stripslashes($sql['quote'] . " ~ <cite>" . $sql['author'] . "</cite>");
} else {
$sel = mysql_query("SELECT * FROM quotes WHERE publish_date='0000-00-00' ORDER BY rand() LIMIT 1");
$sql=mysql_fetch_array($sel);
$id = $sql['quote_id'];
$sql = "UPDATE quotes SET publish_date=CURDATE() WHERE quote_id=$id";
}

idfer

1:40 am on May 6, 2009 (gmt 0)

10+ Year Member



If that's your entire code, then you're not calling mysql_query($sql) at the end of the else block. Could that be it?