Hi
I need to save one variable type date in mysql table but i can't. Please look at the code and help me, please:
$data_compra=date($_POST['data_compray']."/".$_POST['data_compram']."/".$_POST['data_comprad']);
print $data_compra;
//acesso à base de dados
$mysql_id = mysql_connect('localhost', "curso", "123");
mysql_select_db('mariolopes',$mysql_id);
$query="insert into negocios (Codigo,Data_compra)values('Tobias',$data_compra)";
$result=mysql_query($query);
$data_compra is my variable type of date. If I can have date in european format is better (dd/mm/yy) for my project.
Thank you
Cannot save variable type of date
Moderator: General Moderators
-
mariolopes
- Forum Contributor
- Posts: 102
- Joined: Sun May 22, 2005 7:08 am
Re: Cannot save variable type of date
There is no "variable type of date". PHP doesn't have it.mariolopes wrote:$data_compra is my variable type of date.
What you have is a string, and in MySQL strings need quotes around them.
Code: Select all
$query="insert into negocios (Codigo,Data_compra)values('Tobias','$data_compra')";Also, you don't validate the date. Someone could mess with your form and screw up your script. Use checkdate.
-
mariolopes
- Forum Contributor
- Posts: 102
- Joined: Sun May 22, 2005 7:08 am
Re: Cannot save variable type of date
Thank you
Problem solved. My other question: how can I retrieve the data from my table in the format dd-mm-YYYY
Thank you
Problem solved. My other question: how can I retrieve the data from my table in the format dd-mm-YYYY
Thank you
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: Cannot save variable type of date
DATE_FORMAT maybe?
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
-
mariolopes
- Forum Contributor
- Posts: 102
- Joined: Sun May 22, 2005 7:08 am
Re: Cannot save variable type of date
Thank you