I've been having an awful problem all day today...
I have to simply insert a row in the database, and I have tested all variables individually. They all work fine but, as soon as I assemble the query and pass the string as a parameter, a particular variable becomes empty.
echo $command = "INSERT INTO rt_hotran (rte_id, htr_seats, htr_notes) VALUES ('9', '".$array[11]."', '".SQLDate($array[13])."')";
$query = mysql_query($command) or die(mysql_error());
die(mysql_info($query));
The echo outputs correctly: INSERT INTO rt_hotran (rte_id, htr_seats, htr_notes) VALUES ('9', '118', '2012-08-06').
The script does not die, but this error comes up on the mysql_info: Warning: mysql_info() expects parameter 1 to be resource, boolean given.
The SQLDate function simply converts a date from d-m-Y to Y-m-d. What could be the problem? The column type is date in MySQL, but I have also already tried setting it to varchar, but it just writes blank... Could anyone please help me find what's wrong?
Also, $array[11] writes fine, but $array[13] does not. The array has 26 values.
function SQLDate($date)
{
$split = explode("-", $date);
return $split[2]."-".$split[1]."-".$split[0];
}
Array
(
[0] => AZU
[1] => AZUL Linhas Aéreas Brasileiras S/A
[2] => 4000
[3] => E190
[4] => 2
[5] => 3
[6] => 4
[7] => 5
[8] => 6
[9] => S
[10] =>
[11] => 118
[12] => AZU-000265-006
[13] => 13-06-2011
[14] => 14-08-2012
[15] => 04-09-2012
[16] => Nacional
[17] => 1
[18] => SBJV
[19] => Lauro Carneiro de Loyola
[20] => SBKP
[21] => Viracopos
[22] => 06:10
[23] => 07:22
[24] =>
[25] => DATA DE VIGÊNCIA: 04/SET/2012
[26] =>
)
I actually believe that the problem is with the array, as this works:
$array[13] = "13-06-2011";
echo $command = "INSERT INTO rt_hotran (rte_id, htr_seats, htr_notes) VALUES ('9', '".$array[11]."', '".SQLDate($array[13])."')";
$query = mysql_query($command) or die(mysql_error());