PHP MYSQL INSERT DATE PROBLEM

A place for users and developers of the Xataface to discuss and receive support.

PHP MYSQL INSERT DATE PROBLEM

Postby shardison » Tue Sep 25, 2012 6:33 pm

Hi, I am trying to insert into a table data that I am collecting from a different table. It works fine except the date field will not insert. When I echo back the value of the date field it comes back as 'Array'. This doesn't make sense the orginal table shows the date and saves the date just fine. Here is the code:

$con = mysql_connect("localhost:8889","root","root");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("ccap2012",$con);

$client = $record->val('client_id');
$street = $record->val('street');
$city = $record->val('city');
$state = $record->val('state');
$zip = $record->val('zip_code');
$move = $record->val('move_in');
//DATE VALUE HERE

$sql="INSERT INTO Addresses (client_id, street, city, state, zip_code, move_in)
VALUES ('$client','$street','$city','$state','$zip','$move')";
//DATE VARIABLE PROBLEM
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
echo $move;
// ECHO COMES BACK AS 'ARRAY' ???
mysql_close($con);
}


The $move variable is the date value I am trying to insert. All of the other fields insert into the table as expected. Thanks for the help
shardison
 
Posts: 24
Joined: Wed Aug 08, 2012 12:09 pm

Re: PHP MYSQL INSERT DATE PROBLEM

Postby Jean » Wed Sep 26, 2012 4:43 am

Code: Select all
$move = $record->strval('move_in'); //DATE VALUE HERE

strval because a date is a string.

Jean
Jean
 
Posts: 259
Joined: Wed Nov 07, 2007 1:30 am
Location: Pau, France

Re: PHP MYSQL INSERT DATE PROBLEM

Postby shannah » Wed Sep 26, 2012 8:58 am

I also recommend you escape (ie addslashes) to all of the inputs as this opens the possibility of an SQL injection.

-Steve
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: PHP MYSQL INSERT DATE PROBLEM

Postby shardison » Wed Sep 26, 2012 12:55 pm

Jean, and Steve
Thank you very much, That worked like a charm
shardison
 
Posts: 24
Joined: Wed Aug 08, 2012 12:09 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 26 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved