0

I have an SQL query that I am running inside of PHP that is not working. I tried to run it in phpmyadmin and it worked, but when I run it in php it doesn't work. I am getting this SQL error message:

SQL ERROR: 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 'INSERT INTO dgds(Name , Url, 'Date') VALUES ('hdhed', 'gdhd', '12 01 2013'' at line 9

My SQL query is this:

CREATE TABLE ". $tbname ."
(
Id INT NOT NULL AUTO_INCREMENT,
Name VARCHAR( 255 ) ,
Url VARCHAR( 255 ) ,
Date VARCHAR ( 255 ),
PRIMARY KEY ( Id )
);
INSERT INTO ". $tbname ." (`Name` ,  `Url`, 'Date') VALUES ('". $name ."',  '". $url ."', '". $date ."');
2
  • That's 2 queries, not 1. In code, you need to execute them separately. Commented Dec 1, 2013 at 23:55
  • Thanks, that was the problem Commented Dec 2, 2013 at 2:58

1 Answer 1

1
INSERT INTO dgds(`Name` ,  `Url`, 'Date') VALUES 

should be

INSERT INTO dgds(`Name` ,  `Url`, `Date`) VALUES

(mind the backticks vs. the single quotes around Date)

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

Comments

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.