tags:

views:

20

answers:

3

There is a weird code here that I need to make work.. can you please help me correct it .

mysql_query("insert into table(column) values('$var[0]'));
+2  A: 

It looks like you are missing the double quote " at the end of your SQL string.

While you're at it, you should rewrite your query like so:

mysql_query("INSERT INTO table (column) VALUES ('" . mysql_real_escape_string($var[0]) . "')");

...unless you've already escaped $var[0], you should pass all variables through mysql_real_escape_string before interpolating them into an SQL query, to prevent SQL injection attacks.

rjh
A: 

change the way you are using the variable like so:

<?php

mysql_query("insert into table(column) values('".$var[0]."')");

?>

and close the double quotes at the end as you had forgotten to do so.

Steve Obbayi
A: 

Do you really have a table that only needs a single column to be populated?

Can you issue the query through your database admin tool directly, rather than going through PHP? What error do you get?

There are many reasons why your code as it currently stands might be falling over - constraints and permissions being just two. If you can post a helpful error message, we can post some helpful advice...

Martin

Martin Milan