I have a php INSERT for a mysql db that I have a string like a date that “adds” the value instead of just inserting it into the mysql table. When I just echo the value I get '2012-03' It’s a expiration date and must me formatted this way. But in the data base it shows '2009' so it calculates it. What am I doing wrong?
Here’s the insert…
<?php
$Last4CCN = $_POST['CCN'];
$expiration = $_POST['EXPDATE'];
if (!isset($_SESSION)) {
session_start();
}
if (!$conn) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("testing1", $conn);
$last4CCN = mysql_real_escape_string($last4CCN);
$expiration = mysql_real_escape_string($expiration);
$query1 = "
INSERT INTO payment_profile_id (Last4CCN, CCNExpDate)
VALUES ($Last4CCN, $expiration)";
if(mysql_query($query1,$conn))
echo "Update profile_id successfully inserted.<br/>";
else
echo "Update profile_id encountered an error.".mysql_error();
mysql_close($conn)
//$expiration = mysql_real_escape_string($expiration);
//echo $expiration;
?>
Also the MySQL value is varchar(7) for the expdate
Try putting quotes around the date string. It appears you are inserting the value as integers so mysql thinks it is a math expression and not the string
'2012-03'.