Forum Moderators: open

Message Too Old, No Replies

PHP and MySQL Help Needed

queries, If statement, in a PHP file from Database

         

Bigdog1965

10:16 am on Feb 8, 2007 (gmt 0)

10+ Year Member



Hi I’m a newbie that is trying to learn by example. Used a tutorial for creating the PHP file and it just got me to the basic. First off I will try to explain what I’m trying to do.
I have a form that the user fills out the data is put into a MySQL database. Then on my website I have a php page that extracts data from that database and displays it on the page.
I need help with the fallowing
I'm using this line because the user inputs dates that go to the database as 0000-00-00 My date field is set to YYMMDD in the database. So step 1 would be to make the user enter the correct format, preferably MMDD no need for year.
$query = 'DELETE FROM Registration WHERE Race_Date = \'0000-00-00\'';
mysql_query($query);

My second problem is I need for the PHP to delete records older than 15 days. This doesn’t seem to work.
$query = 'DELETE FROM Registration WHERE DATE_SUB(CURDATE(),INTERVAL 15 DAY) <= `Race_Date`';
mysql_query($query);

The third question is, how do I make the second class conditional the default value in the form is Select One which ends up showing on the page if the user doesn’t pick a different one from the pull down. Id like it to not show anything if they don't pick a different option.

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = 'DELETE FROM Registration WHERE Race_Date = \'0000-00-00\'';
mysql_query($query);
$query = 'DELETE FROM Registration WHERE DATE_SUB(CURDATE(),INTERVAL 15 DAY) <= `Race_Date`';
mysql_query($query);
$query="SELECT First_Name, First_Class, Second_Class, Race_Date FROM Registration ORDER BY Race_Date DESC";

$result=mysql_query($query);
$num=mysql_numrows($result);

if ($num==0) {
echo "<b>NO Drivers Registered Yet</b><br>";
}else{
}
mysql_close();

echo "<b>Registered Drivers</b><br>";

$i=0;
while ($i < $num) {
$First_Name=mysql_result($result,$i,"First_Name");
$First_Class=mysql_result($result,$i,"First_Class");
$Second_Class=mysql_result($result,$i,"Second_Class");
$Race_Date=mysql_result($result,$i,"Race_Date");
echo "<b>$First_Name<br>$Race_Date</b><br>$First_Class<br>$Second_Class<hr>";
$i++;
}
?>

coopster

2:52 pm on Feb 21, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, Bigdog1965.

Did you get anywhere on this yet? First, are you setting your date columns in your table as type

DATE
? If not, that would be my first recommendation.