Coloum Count Error


#1

This would seem to be obvious but I can’t find out the error. Here is my insert code.

if(!in_array($file, $filess)){
mysql_query(“INSERT INTO test VALUES(”$file2",“base64_encode($file2)”)")or die(mysql_error());

and this give me the error: Column count doesn’t match value count at row 1

$file2 is generated from an ftp_nlist()

Here is my create table code:

mysql_query(“CREATE TABLE test(
filename TEXT NOT NULL,
encoded TEXT NOT NULL
)”)or die(mysql_error());

as you can see there is 2 colums… I do not see the error, can someone please help me?


#2

Try echoing the mysql_error AFTER the query. Not as a condition of it.

That will eliminate (or perhaps confirm) the CREATE TABLE statement.

Also change the INSERT statement to:
[php]
if(!in_array($file, $filess)){
$file2_encoded=base64_encode($file2);
mysql_query(“INSERT INTO test VALUES(’$file2’,’$file2_encoded’)”)or die(mysql_error());
}
[/php]

I think you are better doing the encoding OUTSIDE of the query.


#3

[php]
$encoded=substr(base64_encode($file2),0,strlen($file2)-2);
echo $encoded;
if(!in_array($file, $filess)){
mysql_query(“INSERT INTO test VALUES($file2,$encoded)”)or die(mysql_error());
[/php]

I tried doing that…still get the same error…[/php]


#4

Well, just for fun lets try this.

[php]
$encoded=substr(base64_encode($file2),0,strlen($file2)-2);
echo $encoded;
if(!in_array($file, $filess)){
$q = “INSERT INTO test VALUES($file2,$encoded)”;
echo “
” . $q;
mysql_query($q)or die(mysql_error());
[/php]

The only reason I would like you to echo out your query is because if your file were to contain any qoutation marks or commas or anything I think it would mess up your query.


#5

There are no extra quotes or anything :roll: I just can’t seem to find any errors I even tried doing “INSERT INTO test VALUES(”$file2","$encoded")


#6

Are you sure you table was created correctly. Not to treat you as though you have not a clue what you are doing, but freaky things happen to even the best of us.

Second of all try adding in the columns right into your query.
You shouldn’t have to, but best to eliminate all possiblities.
[php]

<? $q = "INSERT INTO test (filename,encoded) VALUES ('$file2','$encoded')"; ?>

[/php]

See if that does anything different for you.


#7

Yea it was an error createing the table all along…stupid server… :P


#8

Well, at least ya got it figured out! :)


#9

Yea, Thanks!