date format

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • oneplace
    New Member
    • Sep 2006
    • 1

    date format

    I have the following script that use for the following after i have made my search for a name in my database. I select the name and it bring up this from with all the information of the person. It works great up to the point of the date entries.
    It will bring up the fromat date ok, but when I try and change it and head the submit buton it wipes out the database information. The database stores the information like yyyy-mm-dd hh:mm:ss. I have it fromat to show as month day Year. As long as i re-enter the date as yyy-mm-dd hh:mm:dd it will load the information and the next it is load it show the month day and year and as long as I don't try and change any thing it is fine.
    Code:
    <?php
    
    // PHP DB Control Panel
    //
    include("cn.php");
    include("common.php");
    checklogin();
    
    $msg = "";
    $no = "";
    $lastname = "";
    $firstname = "";
    $address = "";
    $city = "";
    $state = "";
    $postal_code = "";
    $zip = "";
    $country = "";
    $phone_number = "";
    $fax_number = "";
    $car_phone = "";
    $internet_address = "";
    $status = "";
    $type = "";
    $expiration_date = "";
    $begin_date = "";
    $hold_until_date = "";
    $hold_from_date = "";
    $refund = "";
    $internet = "";
    
    if(isset($_POST['Submit']))
    {
    	$lastname = $_POST['Last_Name'];
    	$firstname = $_POST['First_Name'];
            $address = $_POST['Address_1']; 
            $city = $_POST['City']; 
            $state = $_POST['State'];
            $postal_code = $_POST['Postal_Code']; 
            $zip = $_POST['Zip'];
            $country = $_POST['Country']; 
            $phone_number = $_POST['Phone_number']; 
            $fax_number = $_POST['Fax_number']; 
            $car_phone = $_POST['Car_phone']; 
            $internet_address = $_POST['Internet_address']; 
            $status = $_POST['Status']; 
            $type = $_POST['Type'];
            $begin_date = $_POST['Begin_Date']; 
            $expiration_date = $_POST['Expiration_Date'];
            $hold_from_date = $_POST['Hold_From_Date'];
            $hold_until_date = $_POST['Hold_Until_Date']; 
            $refund = $_POST['Refund']; 
            $internet = $_POST['Internet'];  
    	
    	if(!isset($_GET['Subscription_Number']))
    	{
                    $result = mysql_query("Insert into subscriber_information(`Subscription_Number`,`Last_Name`,`First_Name`,`Address_1`,`City`,`State`,`Postal_Code`,`Zip`,`Country`,`Phone_number`,`Fax_number`,`Car_phone`,`Internet_address`,`Status`,`Type`,`Begin_Date`,`Expiration_Date`,`Hold_From_Date`,`Hold_Until_Date`,`Refund`,`Internet`) values('$lastname','$firstname','$address','$city','$state','$postal_code','$zip','$country','$phone_number','$fax_number','$car_number','$internet_address','$status','$type','$expiration_date','$begin_date','$hold_until_date','$hold_from_date','$refund','$internet')");
                    if(!$result)
    {
    
        $msg = 'Error while updating: ' . mysql_error() . "<br />\n";
        die($msg);
    }
    else
    {
        $msg = "Record is saved";
    }
    
    	}
    	else
    	{
    		$result = mysql_query("Update subscriber_information set `Last_Name`='$lastname', `First_Name`='$firstname', `Address_1`='$address', `City`='$city', `State`='$state', `Postal_Code`='$postal_code', `Zip`='$zip', `Country`='$country', `Phone_number`='$phone_number', `Fax_number`='$fax_number', `Car_phone`='$car_phone', `Internet_address`='$internet_address', `Status`='$status', `Type`='$type', `Begin_Date`='$begin_date', `Expiration_Date`='$expiration_date', `Hold_From_Date`='$hold_from_date', `Hold_Until_Date`='$hold_until_date', `Refund`='$refund', `Internet`='$internet' where Subscription_Number =".$_GET['Subscription_Number']);
                    if(!$result)
    {
    
        $msg = 'Error while updating: ' . mysql_error() . "<br />\n";
        die($msg);
    }
    else
    {
        $msg = "Record is updated";
    }
    
    	}
    }
    if(isset($_GET['Subscription_Number']))
    {
    	$result = mysql_query("Select * From subscriber_information where Subscription_Number=".$_GET['Subscription_Number'],$link) or die (mysql_error());
    	while ($row = mysql_fetch_array($result, MYSQL_BOTH)){
    	$lastname = $row['Last_Name'];
    	$firstname = $row['First_Name'];
            $address = $row['Address_1']; 
            $city = $row['City']; 
            $state = $row['State'];
            $postal_code = $row['Postal_Code']; 
            $zip = $row['Zip']; 
            $country = $row['Country']; 
            $phone_number = $row['Phone_number']; 
            $fax_number = $row['Fax_number']; 
            $car_phone = $row['Car_phone']; 
            $internet_address = $row['Internet_address']; 
            $status = $row['Status']; 
            $type = $row['Type'];
            $date = mysql_query("SELECT DATE_FORMAT(Begin_Date, '%M %D %Y')as Begin_Date FROM subscriber_information where Subscription_Number=".$_GET['Subscription_Number'],$link) or die (mysql_error());
            while ($row = mysql_fetch_array($date, MYSQL_BOTH)) {
            $begin_date = $row['Begin_Date'];   
    } 
            $date2 = mysql_query("SELECT DATE_FORMAT(Expiration_Date, '%M %D %Y')as Expiration_Date FROM subscriber_information where Subscription_Number=".$_GET['Subscription_Number'],$link) or die (mysql_error());
            while ($row = mysql_fetch_array($date2, MYSQL_BOTH)) {
            $expiration_date = $row['Expiration_Date'];   
    } 
            $date3 = mysql_query("SELECT DATE_FORMAT(Hold_From_Date, '%M %D %Y')as Hold_From_Date FROM subscriber_information where Subscription_Number=".$_GET['Subscription_Number'],$link) or die (mysql_error());
            while ($row = mysql_fetch_array($date3, MYSQL_BOTH)) {
            $hold_from_date = $row['Hold_From_Date'];   
    } 
            $date4 = mysql_query("SELECT DATE_FORMAT(Hold_Until_Date, '%M %D %Y')as Hold_Until_Date FROM subscriber_information where Subscription_Number=".$_GET['Subscription_Number'],$link) or die (mysql_error());
            while ($row = mysql_fetch_array($date4, MYSQL_BOTH)) {
            $hold_until_date = $row['Hold_Until_Date'];   
    } 
            $refund = $row['Refund']; 
            $internet = $row['Internet'];
            
    }
            
    }
    ?>
    <html>
    <head>
    <title>Admin</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    
    <body>
    <h3>New/Edit Record</h3>
    <p><a href="listrecord.php">List Records</a><br>
      <a href="admin.php">Main</a></p>
    <p><?php echo $msg?><br><?php echo $result?></P>
    <form name="form1" method="post" action="">
      <p>&nbsp;</p>
      <table border="1" align="center" cellpadding="0" cellspacing="0">
        
        <tr>
            <td>Last Name:<input name="Last_Name" type="text" id="Last_Name" value="<?php echo $lastname?>">First Name:<input name="First_Name" type="text" id="First_Name" value="<?php echo $firstname?>"></td>
        </tr>
        <tr> 
            <td>Address:<input name="Address_1" type="text" id="Address_1" value="<?php echo $address?>"></td>
        </tr>
        <tr> 
            <td>City:<input name="City" type="text" id="City" value="<?php echo $city?>">State:<input name="State" type="text" id="State" value="<?php echo $state?>"></td>
        </tr>
        <tr> 
            <td>Postal Code:<input name="Postal_Code" type="text" id="Postal_Code" value="<?php echo $postal_code?>">Zip:<input name="Zip" type="text" id="Zip" value="<?php echo $zip?>"></td>
        </tr>
        <tr> 
            <td>Country:<input name="Country" type="text" id="Country" value="<?php echo $country?>">Phone number:<input name="Phone_number" type="text" id="Phone_number" value="<?php echo $phone_number?>"></td>
        </tr>
        <tr> 
            <td>Fax Number:<input name="Fax_number" type="text" id="Fax_number" value="<?php echo $fax_number?>">Car phone:<input name="Car_phone" type="text" id="Car_phone" value="<?php echo $car_phone?>"></td>
        </tr>
        <tr> 
            <td>Internet address:<input name="Internet_address" type="text" id="Internet_address" value="<?php echo $internet_address?>"></td>
        </tr>
        <tr> 
            <td>Status:<input name="Status" type="text" id="Status" value="<?php echo $status?>">Type:<input name="Type" type="text" id="Type" value="<?php echo $type?>"></td>
        </tr>
        <tr> 
            <td>Begin Date:<input name="Begin_Date" type="text" id="Begin_Date" value="<?php echo $begin_date?>">Expiration Date:<input name="Expiration_Date" type="text" id="Expiration_Date" value="<?php echo $expiration_date?>"></td>
        </tr>
        <tr> 
            <td>Hold From Date:<input name="Hold_From_Date" type="text" id="Hold_From_Date" value="<?php echo $hold_from_date?>">Hold Until Date:<input name="Hold_Until_Date" type="text" id="Hold_Until_Date" value="<?php echo $hold_until_date?>"></td>
        </tr>
        <tr> 
            <td>Refund:<input name="Refund" type="text" id="Refund" value="<?php echo $refund?>">Internet:<input name="Internet" type="text" id="Internet" value="<?php echo $internet?>"></td> 
        </tr>
        <tr> 
          <td>&nbsp;</td>
    
          <td><input type="submit" name="Submit" value="Submit">
            <input type="reset" name="Submit2" value="Reset"></td>
        </tr>
      </table>
      <p>&nbsp; </p>
      <p>&nbsp;</p>
    </form>
    <p><a href="admin.php">Main</a></p>
    
    </body>
    </html>
Working...