0
$SQL="INSERT INTO first_name VALUES (fname) SELECT first_name FROM people WHERE fname = '$fname'";

I'm trying to insert the value 'fname' which is $fname (variable defined by a user) into the column 'first_name'

It's not adding anything but not displaying any errors. Syntax problem?

John AJ
  • 21
  • 1
  • 7
  • Is your table name `first_name`? – Chris Forrence Dec 17 '13 at 21:57
  • 2
    `mysql_error` is the function for returning errors in your query. If I have to read one more post about this I am going to scream. – Tim Seguine Dec 17 '13 at 21:57
  • Are you saving the same value in 2 different tables? – kero Dec 17 '13 at 21:58
  • As another aside, it's highly unsafe to just stick that ol' `$fname` into the query. Since you're using it, I'm assuming that you're using the mysql_* family of functions, [which is BAD](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). The question that I just linked also has resources on alternatives. – Chris Forrence Dec 17 '13 at 22:01
  • possible duplicate of [Wrong syntax for Mysql?](http://stackoverflow.com/questions/20643328/wrong-syntax-for-mysql) – gen_Eric Dec 17 '13 at 22:06

1 Answers1

2

you don't need VALUES() here

INSERT INTO first_name
SELECT first_name 
FROM people WHERE fname = '$fname'
John Woo
  • 258,903
  • 69
  • 498
  • 492