We hope you enjoy your visit.

You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
Wierd Sql Error
Topic Started: May 12 2005, 12:22 AM (458 Views)
Das
Member Avatar
Smells of rich mahogany
[ *  *  *  *  *  *  * ]
I know I have asked alot, but this problem I can't even begin to see where I went wrong. The error message is so weird.
Quote:
 
Unknown column 'tester' in 'field list'

I am trying to fiddel around with a register script. I entered tester as my name and password. Now to the code stuff.
register1.php
 

<html>
<form action="register.php" method="POST">
Enter your desired Username: <input type="text" name="username" />
Enter your desired Password: <input type="text" name="password" />
<input type="submit" />
</form>
</html>


register.php
 

<?
$username = $_POST["username"];
$password = $_POST["password"];


$dbh=mysql_connect ("localhost", "dasein_dasein", "**********") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("dasein_users");

mysql_query("INSERT INTO `members` ('username', 'password', 'type') VALUES ('$username', '$password', 'member')") or die(mysql_error());

?>


It is probly something simple, but I can't begin to troubleshoot with that error message. It makes no sence to me.
Offline Profile Quote Post Goto Top
 
Sani
Member Avatar
Member
[ *  *  *  *  * ]
Could be wrong, but try changing
Code:
 
<?
$username = $_POST["username"];
$password = $_POST["password"];


$dbh=mysql_connect ("localhost", "dasein_dasein", "**********") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("dasein_users");

mysql_query("INSERT INTO `members` ('username', 'password', 'type') VALUES ('$username', '$password', 'member')") or die(mysql_error());

?>
to
Code:
 
<?
$user = $_POST["username"];
$pass = $_POST["password"];


$dbh=mysql_connect ("localhost", "dasein_dasein", "**********") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("dasein_users");

mysql_query("INSERT INTO `members` ('username', 'password', 'type') VALUES ('$user', '$pass', 'member')") or die(mysql_error());

?>
:)
Offline Profile Quote Post Goto Top
 
Das
Member Avatar
Smells of rich mahogany
[ *  *  *  *  *  *  * ]
Overlapping variables?

Anyway when I tried I got a syntax error. This one looks a bit different though.
Quote:
 
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 ''username', 'password', 'type') VALUES ('tester', 'tester', 'me
Offline Profile Quote Post Goto Top
 
Sani
Member Avatar
Member
[ *  *  *  *  * ]
Change
Code:
 
mysql_query("INSERT INTO `members` ('username', 'password', 'type') VALUES ('$user', '$pass', 'member')") or die(mysql_error());
to
Code:
 
mysql_query("INSERT INTO `members` (username, password, type) VALUES ('$username', '$password', 'member')") or die(mysql_error());


;)
Offline Profile Quote Post Goto Top
 
Das
Member Avatar
Smells of rich mahogany
[ *  *  *  *  *  *  * ]
Sucess, but Sani it was:
Quote:
 
mysql_query("INSERT INTO `members` (username, password, type) VALUES ('$user', '$pass', 'member')") or die(mysql_error());


not...

Quote:
 
mysql_query("INSERT INTO `members` (username, password, type) VALUES ('$username', '$password', 'member')") or die mysql_error());


Why didn't
Quote:
 
<?
$username = $_POST["username"];
$password = $_POST["password"];


$dbh=mysql_connect ("localhost", "dasein_dasein", "**********") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("dasein_users");

mysql_query("INSERT INTO `members` ('username', 'password', 'type') VALUES ('$username', '$password', 'member')") or die(mysql_error());

?>

Work?
Offline Profile Quote Post Goto Top
 
Sani
Member Avatar
Member
[ *  *  *  *  * ]
Im not too sure, but its maybe because the variables and table names are the same?
Offline Profile Quote Post Goto Top
 
Das
Member Avatar
Smells of rich mahogany
[ *  *  *  *  *  *  * ]
That makes sense. Why cant Sql errors be more specific?
Offline Profile Quote Post Goto Top
 
Rory
i;m a mess
[ *  *  *  *  *  *  * ]
I think it was more because you had quotes around your column values. That does seem to be the only thing you have changed.

I never use ' around anything except the values to be stored in the table. I don't put them around the table name, or the column name.
Offline Profile Quote Post Goto Top
 
SkItZo
Support Volunteer
[ *  *  * ]
I believe single quotes ' breaks or seperates an SQL query or execution. That's why, if you don't have the function stripslasharrays(); or the likes and you entered in das_ein's it would break the sql query and give you an error. Or, it will register and output your username as das_ein\s
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Technology Chat · Next Topic »
Add Reply