Field list error?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Mythical
Forum Newbie
Posts: 3
Joined: Wed Feb 10, 2010 1:13 pm

Field list error?

Post by Mythical »

I'm trying to create a script for registering new users on my sim site,
but everytime I try to test it out and add a new user to the database,
I get the error:
Error: Unknown column 'username' in 'field list'

I've been led to believe this part of my coding would be where the problem is coming from:

// Finally, create the record.
$newPlayer = @mysql_query("INSERT INTO players (`username`, `password`, `registered`)
VALUES ('$uname', '$pass', '$date')") or die("Error: ".mysql_error());


echo 'You have been registered! You may now <a href=index.php>Log in</a>.';


Anyway to fix this? :)
klevis miho
Forum Contributor
Posts: 413
Joined: Wed Oct 29, 2008 2:59 pm
Location: Albania
Contact:

Re: Field list error?

Post by klevis miho »

I am not sure but use this instead:

$newPlayer = @mysql_query("INSERT INTO players (`username`, `password`, `registered`)
VALUES ('$uname', '$pass', '$date')";) or die("Error: ".mysql_error());
lathangich
Forum Newbie
Posts: 5
Joined: Wed Feb 10, 2010 1:32 pm

Re: Field list error?

Post by lathangich »

Mythical wrote:I'm trying to create a script for registering new users on my sim site,
but everytime I try to test it out and add a new user to the database,
I get the error:
Error: Unknown column 'username' in 'field list'

I've been led to believe this part of my coding would be where the problem is coming from:

// Finally, create the record.
$newPlayer = @mysql_query("INSERT INTO players (`username`, `password`, `registered`)
VALUES ('$uname', '$pass', '$date')") or die("Error: ".mysql_error());


echo 'You have been registered! You may now <a href=index.php>Log in</a>.';


Anyway to fix this? :)
Try to remove single quotes for the field names in the insert statement.Hope this helps!!

$newPlayer = @mysql_query("INSERT INTO players (username, password, registered)
VALUES ('$uname', '$pass', '$date')") or die("Error: ".mysql_error());


Thanks
Lathangi
Mythical
Forum Newbie
Posts: 3
Joined: Wed Feb 10, 2010 1:13 pm

Re: Field list error?

Post by Mythical »

Neither of those worked, I previously tried it without the '`', but it didn't make a difference.

And the first suggestion only told me I made a parse error?
lathangich
Forum Newbie
Posts: 5
Joined: Wed Feb 10, 2010 1:32 pm

Re: Field list error?

Post by lathangich »

Mythical wrote:Neither of those worked, I previously tried it without the '`', but it didn't make a difference.

And the first suggestion only told me I made a parse error?
Usually i try the following way to insert values in database..

Code: Select all

 
    $query = " INSERT into BloomIndex (bloomindexID,startmonth,endmonth,bloomyear,departmentID,title,subtitle)       
           values(null,'$startmonth','$endmonth','$bloomyear','$departmentID','$title', '$subtitle')";
 
    mysql_query($query);
 
    // get the last auto incremented value                                                                                                   
    $bloomindexID = mysql_insert_id();
 
Mythical
Forum Newbie
Posts: 3
Joined: Wed Feb 10, 2010 1:13 pm

Re: Field list error?

Post by Mythical »

Anymore help? i'm still confused :dubious:
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Field list error?

Post by Weirdan »

The error-message is self-explanatory: the players table has no 'username' field.
Post Reply