Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Ola amigos tudo bem?
estou com o seguinte problema:
tenho um formulário que grava algumas informações no banco de dados e duas dessas informações são datas gostaria de saber como faço para converter a data para o formato do MySQL sem ter que ficar digitando ao contrario como faço hoje...
poderia me dar um help!?
ja li diversos fóruns falando sobre implode e explode porem não consegui nenhum resultado
segue a baixo o cod. fonte da pagina em PHP
Seria mais fácil eu usar 3 campos tipo: dia-mês-ano e concatenar no formato que seria gravado no MySQL?
Se sim como seria o procedimento?
Desde já Agradeço a Atenção.
<?php require_once('Connections/conexao.php'); ?>
<?php
//initialize the session
if (!isset($_SESSION)) {
session_start();
}
// Logout the current user.
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
$logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
//to fully log out a visitor we need to clear the session varialbles
$_SESSION['MM_Username'] = NULL;
$_SESSION['MM_UserGroup'] = NULL;
$_SESSION['PrevUrl'] = NULL;
unset($_SESSION['MM_Username']);
unset($_SESSION['MM_UserGroup']);
unset($_SESSION['PrevUrl']);
$logoutGoTo = "index.php";
if ($logoutGoTo) {
header("Location: $logoutGoTo");
exit;
}
}
?>
<?php
if (!isset($_SESSION)) {
session_start();
}
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";
// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {
// For security, start by assuming the visitor is NOT authorized.
$isValid = False;
// When a visitor has logged into this site, the Session variable MM_Username set equal to their username.
// Therefore, we know that a user is NOT logged in if that Session variable is blank.
if (!empty($UserName)) {
// Besides being logged in, you may restrict access to only certain users based on an ID established when they login.
// Parse the strings into arrays.
$arrUsers = Explode(",", $strUsers);
$arrGroups = Explode(",", $strGroups);
if (in_array($UserName, $arrUsers)) {
$isValid = true;
}
// Or, you may restrict access to only certain users based on their username.
if (in_array($UserGroup, $arrGroups)) {
$isValid = true;
}
if (($strUsers == "") && true) {
$isValid = true;
}
}
return $isValid;
}
$MM_restrictGoTo = "index.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {
$MM_qsChar = "?";
$MM_referrer = $_SERVER['PHP_SELF'];
if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0)
$MM_referrer .= "?" . $QUERY_STRING;
$MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
header("Location: ". $MM_restrictGoTo);
exit;
}
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO tbeventos (NomeEventos, OrdemServico, DataInicio, DataFim, HorarioInicio, HorarioFim, LocalEvento, DescricaoEvento, Observacao) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['NomeEventos'], "text"),
GetSQLValueString($_POST['OrdemServico'], "text"),
GetSQLValueString($_POST['DataInicio'], "date"),
GetSQLValueString($_POST['DataFim'], "date"),
GetSQLValueString($_POST['HorarioInicio'], "text"),
GetSQLValueString($_POST['HorarioFim'], "text"),
GetSQLValueString($_POST['LocalEvento'], "text"),
GetSQLValueString($_POST['DescricaoEvento'], "text"),
GetSQLValueString($_POST['Observacao'], "text"));
mysql_select_db($database_conexao, $conexao);
$Result1 = mysql_query($insertSQL, $conexao) or die(mysql_error());
$insertGoTo = "listar-eventos.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Meus Eventos</title>
<script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
<link href="SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" />
<link href="SpryAssets/SpryMenuBarVertical.css" rel="stylesheet" type="text/css" />
<style type="text/css">font-family: Verdana, Geneva, sans-serif;
font-size: 12px;
}</style></head>
<body>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="center" scope="col"><table width="60%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center" scope="col"><h1>Meus Eventos</h1></td>
</tr>
</table></td>
</tr>
<tr>
<td align="center" scope="row"><table width="60%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="44%" align="left" valign="middle" scope="col"><form action="menu_principal.php" method="get" name="pesquisar" id="pesquisar">
Buscar:
<label>
<input type="text" name="busca" id="busca" />
</label>
<label>
<input type="submit" id="enviar" value="Enviar" />
</label>
</form></td>
<td width="56%" height="40" align="center" valign="middle" scope="col"><ul id="MenuBar1" class="MenuBarHorizontal">
<li><a href="menu_principal.php">Home</a></li>
<li><a href="listar-eventos.php">Eventos</a></li>
<li><a href="adiciona-eventos.php">+ Evento</a></li>
<li><a href="<?php echo $logoutAction ?>">Sair</a></li>
</ul></td>
</tr>
</table></td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFF2" scope="row"><table width="60%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center" bgcolor="#FFFFF2" scope="col"><form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
<table align="center">
<tr valign="baseline">
<td align="left" nowrap="nowrap" bgcolor="#F5F5F5"><strong>Nome Evento:</strong></td>
<td bgcolor="#F5F5F5"><input type="text" name="NomeEventos" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td align="left" nowrap="nowrap" bgcolor="#F5F5F5"><strong>Ordem Serviço:</strong></td>
<td bgcolor="#F5F5F5"><input type="text" name="OrdemServico" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td align="left" nowrap="nowrap" bgcolor="#F5F5F5"><strong>Data Inicio:</strong></td>
<td bgcolor="#F5F5F5"><input type="text" name="DataInicio" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td align="left" nowrap="nowrap" bgcolor="#F5F5F5"><strong>Data Fim:</strong></td>
<td bgcolor="#F5F5F5"><input type="text" name="DataFim" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td align="left" nowrap="nowrap" bgcolor="#F5F5F5"><strong>Horario Inicio:</strong></td>
<td bgcolor="#F5F5F5"><input type="text" name="HorarioInicio" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td align="left" nowrap="nowrap" bgcolor="#F5F5F5"><strong>Horario Fim:</strong></td>
<td bgcolor="#F5F5F5"><input type="text" name="HorarioFim" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td align="left" nowrap="nowrap" bgcolor="#F5F5F5"><strong>Local Evento:</strong></td>
<td bgcolor="#F5F5F5"><input type="text" name="LocalEvento" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td align="left" nowrap="nowrap" bgcolor="#F5F5F5"><strong>Descrição Evento:</strong></td>
<td bgcolor="#F5F5F5"><textarea name="DescricaoEvento" cols="40" rows="5"></textarea></td>
</tr>
<tr valign="baseline">
<td align="left" nowrap="nowrap" bgcolor="#F5F5F5"><strong>Observação:</strong></td>
<td bgcolor="#F5F5F5"><textarea name="Observacao" cols="40" rows="5"></textarea></td>
</tr>
<tr valign="baseline">
<td align="left" nowrap="nowrap" bgcolor="#F5F5F5"> </td>
<td bgcolor="#F5F5F5"><input type="submit" value="Inserir registro" /></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1" />
</form>
<p> </p></td>
</tr>
</table></td>
</tr>
</table>
<script type="text/javascript"></script>
</body>
</html>Carregando comentários...