Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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());
share|improve this question
you can edit your question – user1737909 yesterday
@user1737909 sorry about that... thanks. – henriquesirot yesterday
SHOW CREATE TABLE rt_hotran; – Paul Dixon yesterday
@PaulDixon Sorry, I do not undestand what you want me to do... – henriquesirot yesterday

closed as not a real question by deceze, pilsetnieks, Jocelyn, andrewsi, jszumski 23 hours ago

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, see the FAQ.

2 Answers

Finally found out the problem... The array was coming from an Excel spreadsheet, so I there was a \0 hidden somewhere.

I just found it weird that it was a 10-digit date, but in var_dump() it said the string length was 19.

Working fine now, but I was kind of disappointed with the answers, as most people only worry about pointing fingers and supposing the person who asked this is an idiot.

share|improve this answer
To be fair, with the information you provided there was no other conclusion we could come to. It wasn't even totally clear what the problem was. If you could rewrite that question to really talk about the origin and problem of the value, I'll even vote to reopen this question for posterity. As it is it's kind of a jumbled mess though. – deceze 19 hours ago

For an INSERT statement, mysql_query returns a boolean value, not a resource.

If you want to call mysql_info, you can omit the parameter and it will use the last connection you opened.

share|improve this answer
I believe what is happening is that mysql_query is returning false, and mysql_info() expects it to return a resource ID. Anyways, the mysql_info() is not the problem, the problem is that it is not writing it to the database. – henriquesirot yesterday

Not the answer you're looking for? Browse other questions tagged or ask your own question.