Solved

time in php and my sql

Posted on 2007-12-02
11
568 Views
Last Modified: 2012-06-22
The code below it insert   2000-01-01 00:00:00  to   DateGen colum   but  I put date('d-m-Y H:i:s') inline 304 how can i correct it I want to get current date time The colum  type DateGen is date('d-m-Y H:i:s');






<?php
define("EW_PAGE_ID", "add", TRUE); // Page ID
define("EW_TABLE_NAME", 'deposit', TRUE);
?>
<?php
session_start(); // Initialize session data
ob_start(); // Turn on output buffering
?>
<?php include "ewcfg50.php" ?>
<?php include "ewmysql50.php" ?>
<?php include "phpfn50.php" ?>
<?php include "depositinfo.php" ?>
<?php include "userfn50.php" ?>
<?php include "staffinfo.php" ?>
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // Always modified
header("Cache-Control: private, no-store, no-cache, must-revalidate"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
?>
<?php

// Open connection to the database
$conn = ew_Connect();
?>
<?php
$Security = new cAdvancedSecurity();
?>
<?php
if (!$Security->IsLoggedIn()) $Security->AutoLogin();
if (!$Security->IsLoggedIn()) {
      $Security->SaveLastUrl();
      Page_Terminate("login.php");
}
?>
<?php

// Common page loading event (in userfn*.php)
Page_Loading();
?>
<?php

// Page load event, used in current page
Page_Load();
?>
<?php
$deposit->Export = @$_GET["export"]; // Get export parameter
$sExport = $deposit->Export; // Get export parameter, used in header
$sExportFile = $deposit->TableVar; // Get export file, used in header
?>
<?php

// Load key values from QueryString
$bCopy = TRUE;
if (@$_GET["id"] != "") {
  $deposit->id->setQueryStringValue($_GET["id"]);
} else {
  $bCopy = FALSE;
}

// Create form object
$objForm = new cFormObj();

// Process form if post back
if (@$_POST["a_add"] <> "") {
  $deposit->CurrentAction = $_POST["a_add"]; // Get form action
  LoadFormValues(); // Load form values
} else { // Not post back
  if ($bCopy) {
    $deposit->CurrentAction = "C"; // Copy Record
  } else {
    $deposit->CurrentAction = "I"; // Display Blank Record
    LoadDefaultValues(); // Load default values
  }
}

// Perform action based on action code
switch ($deposit->CurrentAction) {
  case "I": // Blank record, no action required
            break;
  case "C": // Copy an existing record
   if (!LoadRow()) { // Load record based on key
      $_SESSION[EW_SESSION_MESSAGE] = "No records found"; // No record found
      Page_Terminate($deposit->getReturnUrl()); // Clean up and return
    }
            break;
  case "A": // ' Add new record
            $deposit->SendEmail = TRUE; // Send email on add success
    if (AddRow()) { // Add successful
      $_SESSION[EW_SESSION_MESSAGE] = "Add New Record Successful"; // Set up success message
      Page_Terminate($deposit->KeyUrl($deposit->getReturnUrl())); // Clean up and return
    } else {
      RestoreFormValues(); // Add failed, restore form values
    }
}

// Render row based on row type
$deposit->RowType = EW_ROWTYPE_ADD;  // Render add type
RenderRow();
?>
<?php include "header.php" ?>
<script type="text/javascript">
<!--
var EW_PAGE_ID = "add"; // Page id

//-->
</script>
<script type="text/javascript">
<!--

function ew_ValidateForm(fobj) {
      if (fobj.a_confirm && fobj.a_confirm.value == "F")
            return true;
      var i, elm, aelm, infix;
      var rowcnt = (fobj.key_count) ? Number(fobj.key_count.value) : 1;
      for (i=0; i<rowcnt; i++) {
            infix = (fobj.key_count) ? String(i+1) : "";
            elm = fobj.elements["x" + infix + "_Damout"];
            if (elm && !ew_CheckNumber(elm.value)) {
                  if (!ew_OnError(elm, "Incorrect floating point number - Damout"))
                        return false;
            }
      }
      return true;
}

//-->
</script>
<script type="text/javascript">
<!--

// js for DHtml Editor
//-->

</script>
<script type="text/javascript">
<!--

// js for Popup Calendar
//-->

</script>
<script type="text/javascript">
<!--
var ew_MultiPagePage = "Page"; // multi-page Page Text
var ew_MultiPageOf = "of"; // multi-page Of Text
var ew_MultiPagePrev = "Prev"; // multi-page Prev Text
var ew_MultiPageNext = "Next"; // multi-page Next Text

//-->
</script>
<script language="JavaScript" type="text/javascript">
<!--

// Write your client script here, no need to add script tags.
// To include another .js script, use:
// ew_ClientScriptInclude("my_javascript.js");
//-->

</script>
<p><span class="phpmaker">Add to TABLE: deposit<br><br><a href="<?php echo $deposit->getReturnUrl() ?>">Go Back</a></span></p>
<?php
if (@$_SESSION[EW_SESSION_MESSAGE] <> "") { // Mesasge in Session, display
?>
<p><span class="ewmsg"><?php echo $_SESSION[EW_SESSION_MESSAGE] ?></span></p>
<?php
  $_SESSION[EW_SESSION_MESSAGE] = ""; // Clear message in Session
}
?>
<form name="fdepositadd" id="fdepositadd" action="depositadd.php" method="post" onSubmit="return ew_ValidateForm(this);">
<p>
<input type="hidden" name="a_add" id="a_add" value="A">
<table class="ewTable">
  <tr class="ewTableRow">
    <td class="ewTableHeader">Memberid</td>
    <td<?php echo $deposit->Memberid->CellAttributes() ?>><span id="cb_x_Memberid">
<select id="x_Memberid" name="x_Memberid" onChange="ew_UpdateOpt(this.form.x_Name, ar_x_Name, this);"<?php echo $deposit->Memberid->EditAttributes() ?>>
<!--option value="">Please Select</option-->
<?php
if (is_array($deposit->Memberid->EditValue)) {
      $arwrk = $deposit->Memberid->EditValue;
      $rowswrk = count($arwrk);
      for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
            $selwrk = (strval($deposit->Memberid->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected" : "";      
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
</option>
<?php
                  }
}
?>
</select>
</span></td>
  </tr>
<input type="hidden" name="x_Dtype" id="x_Dtype" value="<?php echo ew_HtmlEncode($deposit->Dtype->CurrentValue) ?>">
  <tr class="ewTableAltRow">
    <td class="ewTableHeader">Name</td>
    <td<?php echo $deposit->Name->CellAttributes() ?>><span id="cb_x_Name">
<select id="x_Name" name="x_Name"<?php echo $deposit->Name->EditAttributes() ?>>
<!--option value="">Please Select</option-->
<?php
if (is_array($deposit->Name->EditValue)) {
      $arwrk = $deposit->Name->EditValue;
      $rowswrk = count($arwrk);
      for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
            $selwrk = (strval($deposit->Name->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected" : "";      
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
</option>
<?php
                  }
}
?>
</select>
<?php
$jswrk = "";
if (is_array($deposit->Name->EditValue)) {
      $arwrk = $deposit->Name->EditValue;
      $arwrkcnt = count($arwrk);
      for ($rowcntwrk = 1; $rowcntwrk < $arwrkcnt; $rowcntwrk++) {
            $jswrk .= "ar_x_Name[" . (($rowcntwrk-1)*4) . "] = '" . str_replace("'", "\'", strval($arwrk[$rowcntwrk][0])) . "';"; // Value
            $jswrk .= "ar_x_Name[" . (($rowcntwrk-1)*4+1) . "] = '" . str_replace("'", "\'", strval($arwrk[$rowcntwrk][1])) . "';"; // Display field 1
            $jswrk .= "ar_x_Name[" . (($rowcntwrk-1)*4+2) . "] = '';";
            $jswrk .= "ar_x_Name[" . (($rowcntwrk-1)*4+3) . "] = '" . str_replace("'", "\'", strval($arwrk[$rowcntwrk][2])) . "';"; // Filter field
      }
}
?>
<script type="text/javascript">
<!--
var ar_x_Name = new Array();
<?php echo $jswrk ?>

//-->
</script>
</span></td>
  </tr>
  <tr class="ewTableRow">
    <td class="ewTableHeader">Damout</td>
    <td<?php echo $deposit->Damout->CellAttributes() ?>><span id="cb_x_Damout">
<input type="text" name="x_Damout" id="x_Damout" title="" size="30" value="<?php echo $deposit->Damout->EditValue ?>"<?php echo $deposit->Damout->EditAttributes() ?>>
</span></td>
  </tr>
<input type="hidden" name="x_DateGen" id="x_DateGen" value="<?php echo ew_HtmlEncode($deposit->DateGen->CurrentValue) ?>">
<input type="hidden" name="x_staff" id="x_staff" value="<?php echo ew_HtmlEncode($deposit->staff->CurrentValue) ?>">
</table>
<p>
<input type="submit" name="btnAction" id="btnAction" value="    Add    ">
</form>
<script language="JavaScript">
<!--
var f = document.fdepositadd;
ew_UpdateOpt(f.x_Name, ar_x_Name, f.x_Memberid);

//-->
</script>
<script language="JavaScript" type="text/javascript">
<!--

// Write your table-specific startup script here
// document.write("page loaded");
//-->

</script>
<?php include "footer.php" ?>
<?php

// If control is passed here, simply terminate the page without redirect
Page_Terminate();

// -----------------------------------------------------------------
//  Subroutine Page_Terminate
//  - called when exit page
//  - clean up connection and objects
//  - if url specified, redirect to url, otherwise end response
function Page_Terminate($url = "") {
      global $conn;

      // Page unload event, used in current page
      Page_Unload();

      // Global page unloaded event (in userfn*.php)
      Page_Unloaded();

       // Close Connection
      $conn->Close();

      // Go to url if specified
      if ($url <> "") {
            ob_end_clean();
            header("Location: $url");
      }
      exit();
}
?>
<?php

// Load default values
function LoadDefaultValues() {
      global $deposit;
      $deposit->Dtype->CurrentValue = pic;
      $deposit->DateGen->CurrentValue = date('d-m-Y H:i:s');
      $deposit->staff->CurrentValue = CurrentUserName();
}
?>
<?php

// Load form values
function LoadFormValues() {

      // Load from form
      global $objForm, $deposit;
      $deposit->Memberid->setFormValue($objForm->GetValue("x_Memberid"));
      $deposit->Dtype->setFormValue($objForm->GetValue("x_Dtype"));
      $deposit->Name->setFormValue($objForm->GetValue("x_Name"));
      $deposit->Damout->setFormValue($objForm->GetValue("x_Damout"));
      $deposit->DateGen->setFormValue($objForm->GetValue("x_DateGen"));
      $deposit->DateGen->CurrentValue = ew_UnFormatDateTime($deposit->DateGen->CurrentValue, 7);
      $deposit->staff->setFormValue($objForm->GetValue("x_staff"));
}

// Restore form values
function RestoreFormValues() {
      global $deposit;
      $deposit->Memberid->CurrentValue = $deposit->Memberid->FormValue;
      $deposit->Dtype->CurrentValue = $deposit->Dtype->FormValue;
      $deposit->Name->CurrentValue = $deposit->Name->FormValue;
      $deposit->Damout->CurrentValue = $deposit->Damout->FormValue;
      $deposit->DateGen->CurrentValue = $deposit->DateGen->FormValue;
      $deposit->DateGen->CurrentValue = ew_UnFormatDateTime($deposit->DateGen->CurrentValue, 7);
      $deposit->staff->CurrentValue = $deposit->staff->FormValue;
}
?>
<?php

// Load row based on key values
function LoadRow() {
      global $conn, $Security, $deposit;
      $sFilter = $deposit->SqlKeyFilter();
      if (!is_numeric($deposit->id->CurrentValue)) {
            return FALSE; // Invalid key, exit
      }
      $sFilter = str_replace("@id@", ew_AdjustSql($deposit->id->CurrentValue), $sFilter); // Replace key value

      // Call Row Selecting event
      $deposit->Row_Selecting($sFilter);

      // Load sql based on filter
      $deposit->CurrentFilter = $sFilter;
      $sSql = $deposit->SQL();
      if ($rs = $conn->Execute($sSql)) {
            if ($rs->EOF) {
                  $LoadRow = FALSE;
            } else {
                  $LoadRow = TRUE;
                  $rs->MoveFirst();
                  LoadRowValues($rs); // Load row values

                  // Call Row Selected event
                  $deposit->Row_Selected($rs);
            }
            $rs->Close();
      } else {
            $LoadRow = FALSE;
      }
      return $LoadRow;
}

// Load row values from recordset
function LoadRowValues(&$rs) {
      global $deposit;
      $deposit->id->setDbValue($rs->fields('id'));
      $deposit->Memberid->setDbValue($rs->fields('Memberid'));
      $deposit->Dtype->setDbValue($rs->fields('Dtype'));
      $deposit->Name->setDbValue($rs->fields('Name'));
      $deposit->Damout->setDbValue($rs->fields('Damout'));
      $deposit->DateGen->setDbValue($rs->fields('DateGen'));
      $deposit->Timestamp->setDbValue($rs->fields('Timestamp'));
      $deposit->staff->setDbValue($rs->fields('staff'));
}
?>
<?php

// Render row values based on field settings
function RenderRow() {
      global $conn, $Security, $deposit;

      // Call Row Rendering event
      $deposit->Row_Rendering();

      // Common render codes for all row types
      // Memberid

      $deposit->Memberid->CellCssStyle = "";
      $deposit->Memberid->CellCssClass = "";

      // Dtype
      $deposit->Dtype->CellCssStyle = "";
      $deposit->Dtype->CellCssClass = "";

      // Name
      $deposit->Name->CellCssStyle = "";
      $deposit->Name->CellCssClass = "";

      // Damout
      $deposit->Damout->CellCssStyle = "";
      $deposit->Damout->CellCssClass = "";

      // DateGen
      $deposit->DateGen->CellCssStyle = "";
      $deposit->DateGen->CellCssClass = "";

      // staff
      $deposit->staff->CellCssStyle = "";
      $deposit->staff->CellCssClass = "";
      if ($deposit->RowType == EW_ROWTYPE_VIEW) { // View row
      } elseif ($deposit->RowType == EW_ROWTYPE_ADD) { // Add row

            // Memberid
            $deposit->Memberid->EditCustomAttributes = "";
            $sSqlWrk = "SELECT `ID`, `ID` FROM `listname`";
            $rswrk = $conn->Execute($sSqlWrk);
            $arwrk = ($rswrk) ? $rswrk->GetRows() : array();
            if ($rswrk) $rswrk->Close();
            array_unshift($arwrk, array("", "Please Select"));
            $deposit->Memberid->EditValue = $arwrk;

            // Dtype
            $deposit->Dtype->EditCustomAttributes = "";
            $deposit->Dtype->CurrentValue = pic;

            // Name
            $deposit->Name->EditCustomAttributes = "";
            $sSqlWrk = "SELECT `Name`, `Name`, `ID` FROM `listname`";
            $rswrk = $conn->Execute($sSqlWrk);
            $arwrk = ($rswrk) ? $rswrk->GetRows() : array();
            if ($rswrk) $rswrk->Close();
            array_unshift($arwrk, array("", "Please Select", ""));
            $deposit->Name->EditValue = $arwrk;

            // Damout
            $deposit->Damout->EditCustomAttributes = "";
            $deposit->Damout->EditValue = $deposit->Damout->CurrentValue;

            // DateGen
            $deposit->DateGen->EditCustomAttributes = "";
            $deposit->DateGen->CurrentValue = ew_FormatDateTime(date('d-m-Y H:i:s'), 7);

            // staff
            $deposit->staff->EditCustomAttributes = "";
            $deposit->staff->CurrentValue = CurrentUserName();
      } elseif ($deposit->RowType == EW_ROWTYPE_EDIT) { // Edit row
      } elseif ($deposit->RowType == EW_ROWTYPE_SEARCH) { // Search row
      }

      // Call Row Rendered event
      $deposit->Row_Rendered();
}
?>
<?php

// Add record
function AddRow() {
      global $conn, $Security, $deposit;

      // Check for duplicate key
      $bCheckKey = TRUE;
      $sFilter = $deposit->SqlKeyFilter();
      if (trim(strval($deposit->id->CurrentValue)) == "") {
            $bCheckKey = FALSE;
      } else {
            $sFilter = str_replace("@id@", ew_AdjustSql($deposit->id->CurrentValue), $sFilter); // Replace key value
      }
      if (!is_numeric($deposit->id->CurrentValue)) {
            $bCheckKey = FALSE;
      }
      if ($bCheckKey) {
            $rsChk = $deposit->LoadRs($sFilter);
            if ($rsChk && !$rsChk->EOF) {
                  $_SESSION[EW_SESSION_MESSAGE] = "Duplicate value for primary key";
                  $rsChk->Close();
                  return FALSE;
            }
      }
      $rsnew = array();

      // Field Memberid
      $deposit->Memberid->SetDbValueDef($deposit->Memberid->CurrentValue, NULL);
      $rsnew['Memberid'] =& $deposit->Memberid->DbValue;

      // Field Dtype
      $deposit->Dtype->SetDbValueDef($deposit->Dtype->CurrentValue, NULL);
      $rsnew['Dtype'] =& $deposit->Dtype->DbValue;

      // Field Name
      $deposit->Name->SetDbValueDef($deposit->Name->CurrentValue, NULL);
      $rsnew['Name'] =& $deposit->Name->DbValue;

      // Field Damout
      $deposit->Damout->SetDbValueDef($deposit->Damout->CurrentValue, NULL);
      $rsnew['Damout'] =& $deposit->Damout->DbValue;

      // Field DateGen
      $deposit->DateGen->SetDbValueDef(ew_UnFormatDateTime($deposit->DateGen->CurrentValue, 7), NULL);
      $rsnew['DateGen'] =& $deposit->DateGen->DbValue;

      // Field staff
      $deposit->staff->SetDbValueDef($deposit->staff->CurrentValue, NULL);
      $rsnew['staff'] =& $deposit->staff->DbValue;

      // Call Row Inserting event
      $bInsertRow = $deposit->Row_Inserting($rsnew);
      if ($bInsertRow) {
            $conn->raiseErrorFn = 'ew_ErrorFn';
            $AddRow = $conn->Execute($deposit->InsertSQL($rsnew));
            $conn->raiseErrorFn = '';
      } else {
            if ($deposit->CancelMessage <> "") {
                  $_SESSION[EW_SESSION_MESSAGE] = $deposit->CancelMessage;
                  $deposit->CancelMessage = "";
            } else {
                  $_SESSION[EW_SESSION_MESSAGE] = "Insert cancelled";
            }
            $AddRow = FALSE;
      }
      if ($AddRow) {
            $deposit->id->setDbValue($conn->Insert_ID());
            $rsnew['id'] =& $deposit->id->DbValue;

            // Call Row Inserted event
            $deposit->Row_Inserted($rsnew);
      }
      return $AddRow;
}
?>
<?php

// Page Load event
function Page_Load() {

      //echo "Page Load";
}

// Page Unload event
function Page_Unload() {

      //echo "Page Unload";
}
?>
0
Comment
Question by:teera
  • 6
  • 5
11 Comments
 
LVL 21

Expert Comment

by:nizsmo
ID: 20391873
Since the date is in this format: 2000-01-01 00:00:00

try:
date('Y-m-Y H:i:s');
0
 
LVL 21

Accepted Solution

by:
nizsmo earned 500 total points
ID: 20391875
Correction sorry! try:
try:
date('Y-m-d H:i:s');
0
 

Author Comment

by:teera
ID: 20391910
it insert work 50 percent it insert  2007-12-03 00:00:00 but the time is still not in sert please help
0
 

Author Comment

by:teera
ID: 20391926
$deposit->DateGen->CurrentValue = ew_FormatDateTime(date('Y-m-d H:i:s'), 7);

may be this line cause problem  inline 449    what is 7 ido ineed to change it
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20391927
echo date('Y-m-d H:i:s');

what do you see? Now try and copy and paste this into your one of your entries in phpmyadmin, does it insert properly?
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 21

Expert Comment

by:nizsmo
ID: 20391930
just as a test try without the function:
$deposit->DateGen->CurrentValue = date('Y-m-d H:i:s');
0
 

Author Comment

by:teera
ID: 20391958
2007-12-03 02:11:49 i can add with phpmyadmin
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20391964
did this work?
$deposit->DateGen->CurrentValue = date('Y-m-d H:i:s');
0
 

Author Comment

by:teera
ID: 20391988
it work 100 percent  but when the pro gram list it show black but when i look with php admin it work
0
 

Author Comment

by:teera
ID: 20392008
Thank you very much for help
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20394425
glad to help :)
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now