I am separating the month, day and year for use in a drop down menu with the strtotime() function.
There are two dates I'm using this on. The first one works no problem and I have NO idea why the second will not pick up these $_POST values.
Code: Select all
<?php
$query = mysql_query("SELECT products.registration_date, products.renewal_date, products.price, catagories.name, subCatagories.name, items.name, items.model_num, items.price FROM products, catagories, subCatagories, items WHERE products.id=$product_id AND products.product_id=items.items_id AND subCatagories.subcat_id=items.subcat_id AND catagories.cat_id=subCatagories.cat_id");
$client_product = mysql_fetch_array($query) or die ('Database Error: ' . mysql_error());
$_POST['month'] = date('n', strtotime($client_product[0]));
$_POST['day'] = date('j', strtotime($client_product[0]));
$_POST['year'] = date('Y', strtotime($client_product[0]));
$_POST['month1'] = date('n', strtotime($client_product[1]));
$_POST['day1'] = date('j', strtotime($client_product[1]));
$_POST['year1'] = date('Y', strtotime($client_product[1]));
?>
<form action="" method="post">
<table width="440" class="form" style="margin:auto;">
<tr><td colspan="2" class="fieldarea" style="text-align:center;"><input type="hidden" name="id" value="<?php echo $product_id; ?>" /><b>Client Products</b></td></tr>
<?php
if( $error_code > 0 ){
echo "<tr align='center'><td colspan='2' class='". $tbl_class[$error_code] ."'>$user_message</td></tr>";
}
?>
<tr align="center"><td colspan="2"><?php echo $client_product[3]; ?> - <?php echo $client_product[4]; ?></td></tr>
<tr><td align="right">Registration Date:</td><td>
<?php
echo "<SELECT NAME='month'>";
foreach( $months AS $key => $value ){
echo "<OPTION VALUE='$key'";
if( $_POST['month'] == $key ) { echo " SELECTED"; }
echo ">$value</OPTION>";
}
echo "</select>";
echo "<SELECT NAME='day'>";
for( $days=1; $days<=31; $days++ ){
echo "<OPTION VALUE='$days'";
if( $_POST['day'] == $days ) { echo " SELECTED"; }
echo ">$days</OPTION>";
}
echo "</select>";
?>
<INPUT TYPE="text" maxlength="4" NAME="year" VALUE="<?php echo $_POST['year']; ?>" style="width:4em; text-align:center; font-weight:bold;"></td></tr>
<tr><td align="right">Renewal Date:</td><td>
<?php
echo "<SELECT NAME='month1'>";
foreach( $months AS $key => $value ){
echo "<OPTION VALUE='$key'";
if( $_POST['month1'] == $key ) { echo " SELECTED"; }
echo ">$value</OPTION>";
}
echo "</select>";
echo "<SELECT NAME='day1'>";
for( $days=1; $days<=31; $days++ ){
echo "<OPTION VALUE='$days'";
if( $_POST['day1'] == $days ) { echo " SELECTED"; }
echo ">$days</OPTION>";
}
echo "</select>";
?>
<INPUT TYPE="text" maxlength="4" NAME="year1" VALUE="<?php echo $_POST['year1']; ?>" style="width:4em; text-align:center; font-weight:bold;"></td></tr>
<tr><td align="right">Renewal Date:</td><td><INPUT TYPE="text" NAME="test" VALUE="<?php echo $client_product[1]; ?>" style="width:14em; text-align:center; font-weight:bold;"></td></tr>
<tr align="center"><td colspan="2"><p class="submit"><input type="submit" name="update_details" value="Update Client Product Details" /></p><p class="submit"><input type="submit" name="delete_product" value="Delete Product" /></p></td></tr>
</table>
</form>
Ok, so I thought there was something wrong with $client_product[1] value. I just put it into a text box and it prints 2100-02-03, just what is in the database.
Just for fun, to check my own syntax above I changed to $client_product[0] to $client_product[1] and $client_product[1] to $client_product[0]. This puts the data in the wrong places, but it again only works on the $client_product[0] value.
Any ideas would be great.