PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
mariolopes
Forum Contributor
Posts: 102 Joined: Sun May 22, 2005 7:08 am
Post
by mariolopes » Fri Mar 12, 2010 10:37 am
Hi
This problem drives me crazy. I try to update a field type date but i can't and i don't know why. Here is my code:
Code: Select all
<?php
$mysql_id = mysql_connect('localhost', 'xxx', 'xxx');
mysql_select_db('mariolopes',$mysql_id);
$query="update negocios set Data_venda='$_POST[hoje]' where Codigo='$_POST[codigo]'";
$result=mysql_query($query);
if(!$result){
echo(mysql_error());
}
else{
header("location:darcomopago.php");
}
?>
How can i get the date format in my server (d-m-y or y-m-d or ...)?
Thank you
mariolopes
Forum Contributor
Posts: 102 Joined: Sun May 22, 2005 7:08 am
Post
by mariolopes » Fri Mar 12, 2010 11:01 am
It works like this
Code: Select all
<?php
$mysql_id = mysql_connect('localhost', 'mariolopes', 'freixo');
mysql_select_db('mariolopes',$mysql_id);
$lixo=$_POST['hoje'];
$bolas=explode ("/",$lixo);
$dia=$bolas[0];
$mes=$bolas[1];
$ano=$bolas[2];
$data_venda="'".$ano."-".$mes."-".$dia."'";
$query="update negocios set Vendido='S', Preco_venda='$_POST[preco]', Data_venda=$data_venda where Codigo='$_POST[codigo]'";
$result=mysql_query($query);
if(!$result){
echo(mysql_error());
}
else{
header("location:darcomopago.php");
}
?>
What a headache.
lshaw
Forum Commoner
Posts: 69 Joined: Mon Apr 20, 2009 3:40 pm
Location: United Kingdom
Post
by lshaw » Fri Mar 12, 2010 11:03 am
What date format are you submitting in. Assuming you are submitting 24th jan 2009 or vitually any date format, and your mysql field type is DATE and not DATETIME
Code: Select all
//validate the time here
$time=strtotime($_POST['hoje']); //change to php format 1234567890
$date=date("Y-m-d",$time); //change to mysql format
//insert it here
mariolopes
Forum Contributor
Posts: 102 Joined: Sun May 22, 2005 7:08 am
Post
by mariolopes » Sun Mar 14, 2010 1:40 pm
Thank you
I'll try it