Page 1 of 1

Field list error?

Posted: Wed Feb 10, 2010 1:27 pm
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? :)

Re: Field list error?

Posted: Wed Feb 10, 2010 2:21 pm
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());

Re: Field list error?

Posted: Wed Feb 10, 2010 2:47 pm
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

Re: Field list error?

Posted: Wed Feb 10, 2010 3:10 pm
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?

Re: Field list error?

Posted: Wed Feb 10, 2010 3:21 pm
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();
 

Re: Field list error?

Posted: Thu Feb 11, 2010 11:35 am
by Mythical
Anymore help? i'm still confused :dubious:

Re: Field list error?

Posted: Thu Feb 11, 2010 12:15 pm
by Weirdan
The error-message is self-explanatory: the players table has no 'username' field.