0

Trying to perform this query:

$result = "INSERT INTO `user`(`username`, `ip`, `country`) VALUES ('$username','$location[ip]','$location[country]')";

@mysql_query($result) or die("Error:". mysql_error());

Tried ever combination of single and double quotes, but constantly getting error:

Error:Unknown column 'ip' in 'field list'

Column 'ip' does exist in database, when I echo out query and run it in PHPMyAdmin it works perfectly

INSERT INTO `user`(`username`, `ip`, `country`) VALUES ('name32','127.0.0.1','mycountry')
8
  • 3
    post the table structure Commented Jul 5, 2013 at 11:41
  • Print out the sql the is being generated, that will give you an idea if your query is correct. Commented Jul 5, 2013 at 11:44
  • 3
    Most likley, there's no ip field in the user table. Commented Jul 5, 2013 at 11:45
  • how can I run echoed query in PHPMyAdmin then? Commented Jul 5, 2013 at 11:48
  • What if you do mysql_query("INTO user(username, ip, country) VALUES ('name32','127.0.0.1','mycountry')") or die(mysql_error() ); does that work? Commented Jul 5, 2013 at 11:49

2 Answers 2

1

Change your SQL query like this

$result = "INSERT INTO `user` (`username`, `ip`, `country`) VALUES ('".$username."','".$location['ip']."','".$location['country']."')";
Sign up to request clarification or add additional context in comments.

1 Comment

@user2411147 Try this. Is that work @mysql_query("INSERT INTO user (username, ip, country) VALUES ('name32','127.0.0.1','mycountry')") or die("Error:". mysql_error()); Or you still get the same error??
1

im thinking that you might have made a typo in the database? I use IP every once in a while and im never having any problems. Could it be you named the column IP (uppercased)? That might break things

To make sure the name is correct, you could change the name to 'something' and change the query. If it starts working, its something in the names-area, otherwise you know for sure its not that

3 Comments

When I swap 'ip' with 'country', than country makes an error. I don't understand why echoing result out and manually running query makes no error
check database connections once
Yep, different DB was selected, containing same table but different columns. Such a stupid mistake. Thanks.

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.