0

It's really not my first SQL query;), but ...!, I've a weird error : I am doing an import from a CSV file into my db, and the query returns an error with mysql_query, and in phpmyadmin, if I copy/paste the query, all is ok.

$result = mysql_query ($ sql);
echo $ sql. "=>". $result. ','. Mysql_error ($this-> cnx). '<br> cnx ='. $this-> cnx. '<br>';

In the echo :

INSERT INTO tiny_url (`id`, `url`, `tiny_url`, `page_rank`, `link_name`, `destination_url`, `anchor`, `active`) VALUES (NULL, "111", "222", 3, "444", "555", 1,1)
=>, You have an error in your SQL syntax; check the manual That corresponds to your MySQL server version for the right syntax to use near '
'At line 3
cnx = Resource id # 27

and if I do that : it works:

$sql = 'INSERT INTO tiny_url (`id`, `url`, `tiny_url`, `page_rank`, `link_name`, `destination_url`, `anchor`, `active `) VALUES (NULL," 111 "," 222 ", 3," 444 "," 555 ", 1,1) ';

$result = mysql_query ($sql);
echo $sql. "=>". $result. ','. mysql_error($this-> cnx). '<br> cnx ='. $this-> cnx. '<br>';

Can U help me please ?

Fab

4
  • 1
    please don't use mysql_* functions, it's deprecated (see red box) and vulnerable to sql-injection. Use PDO or MySQLi. Commented Aug 30, 2012 at 15:11
  • Can you show the CREATE TABLE for your table? Commented Aug 30, 2012 at 15:13
  • Can you share the code that involves $this->cnx? It looks like you are trying to include an object or resource instead of a number? Commented Aug 30, 2012 at 15:14
  • 1
    Is there any reason you have spaces around your integers in your INSERT? ...VALUES (NULL," 111 "," 222 "... Commented Aug 30, 2012 at 15:15

2 Answers 2

1

Your columns is called active (followed by a space).

Sign up to request clarification or add additional context in comments.

Comments

0

I've found the problem : In my code, i've added this

$sql .= ")<br>";

Of course, no html code is allowed in a query.. of course.

Et voila... :(

Fab

2 Comments

According to this - the second query should have failed.
Thanks everyone your for all your help, but i've found my problem... it was a silly error... :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.