Page 1 of 2
Unknown column 'N' in 'field list'
Posted: Fri Jul 21, 2006 2:12 pm
by Assured99
ok so i am adjusting my Data base to reflect user access i am using a drop down box.
1. Is it ok to use a drop down box with PHP? and are there any special things i need to do to post them to the database (MySQL)
2. I am getting this Error: Unknown column 'N' in 'field list' Ive Searched for the N Field in the database and the php Script with no avail.
Code: Select all
$sql = "INSERT INTO $table_name VALUES
('$_POST[firstname]', '$_POST[lastname]', $_POST[company], '$_POST[username]', password('$_POST[password]'), 'Users', '', '', '$pchange',
'$_POST[email]', $_POST[access], '$default_url', '$verify', '')";
And here is the code for the drop down box:
Code: Select all
<span style="font-size: 14px"><strong style="font-weight: 400"><font face="Tahoma">Type
of Access Requested: </font></strong></span><font face="Tahoma"><font size="2"><BR>
</font><font face="Tahoma" size="1">
<label>
<select name="access" >
<option>Patient</option>
<option>Referral</option>
<option>Employee</option>
<option selected>Please Select Access Type</option>
</select>
</label>
</font></font></p>
Can 'n' Field stand for something ????
Sorry if this is a repost i did a quick search
Posted: Fri Jul 21, 2006 2:16 pm
by kbrown3074
Could your $table_name be evaluating to "N"? Nothing jumps out at me. Do you have other insert lines on the page this code is from?
Posted: Fri Jul 21, 2006 2:21 pm
by Assured99
Weirdan | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Table name is set to $table_name ="authorize"; Which is correct
I only ran into this problem after adding the drop down box to select access here the the complete form:
[syntax="html"]<FORM METHOD="POST" ACTION="register.php" onSubmit="return Form1_Validator(this)" language="JavaScript" name="Form1">
<P style="margin-top: 0; margin-bottom: 0"><font face="Tahoma">
<span style="font-size: 14px"><strong style="font-weight: 400">First Name:</strong></span><font size="2"><BR>
</font><font face="Tahoma" size="1">
<INPUT NAME="firstname" SIZE=25 MAXLENGTH=50></font></font></p>
<strong style="font-weight: 400"><span class="style4">Last Name</span><font size="2">:</font></strong><font size="2"><BR>
</font><font face="Tahoma" size="1">
<INPUT NAME="lastname" SIZE=25 MAXLENGTH=50><br>
</font><span style="font-size: 14px"><strong style="font-weight: 400">Company:</strong></span><font size="2"><BR>
</font><font face="Tahoma" size="1">
<INPUT NAME="company" SIZE=25 MAXLENGTH=50>
<br>
</font><font face="Tahoma"><span class="style4"><font face="Tahoma">Username:</font></span></font><font face="Tahoma" size="1"><font face="Tahoma" size="1"><br>
<INPUT NAME="username" SIZE=25 MAXLENGTH=50>
</font></font>
<P style="margin-top: 0; margin-bottom: 0"><font face="Tahoma"><strong style="font-weight: 400">Password:</strong><font size="2"><BR>
</font><font face="Tahoma" size="1">
<INPUT TYPE="password" NAME="password" SIZE=25 MAXLENGTH=25><br>
</font>Confirm Password:<font face="Tahoma" size="1"><br>
<INPUT TYPE="password" NAME="confirm" SIZE=25 MAXLENGTH=25></font></font></p>
<P style="margin-top: 0"><span style="font-size: 14px"><strong style="font-weight: 400">
<font face="Tahoma">E-Mail Address</font></strong><font face="Tahoma"><strong style="font-weight: 400">:</strong></font></span><font face="Tahoma"></font><font face="Tahoma"><font size="2"><BR>
</font><font face="Tahoma" size="1">
<INPUT TYPE="text" NAME="email" SIZE=25 MAXLENGTH=100></font></font></p>
<P><span style="font-size: 14px"><strong style="font-weight: 400"><font face="Tahoma">Type
of Access Requested: </font></strong></span><font face="Tahoma"><font size="2"><BR>
</font><font face="Tahoma" size="1">
<label>
<select name="access" >
<option>Patient</option>
<option>Referral</option>
<option>Employee</option>
<option selected>Please Select Access Type</option>
</select>
</label>
</font></font></p>
<P style="margin-top: 0; margin-bottom: 0">
<INPUT TYPE="submit" NAME="submit" VALUE="Submit" style="font-family: Tahoma"></p>
</FORM>
Weirdan | Please use[/syntax]Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Fri Jul 21, 2006 2:27 pm
by Ward
FYI, it's not correct syntax to specify a string array key without quotes. If you turn on error reporting you'll see that each time you do this a notice is generated.
Should be
(double or single quotes are okay)
Posted: Fri Jul 21, 2006 3:06 pm
by Assured99
But that still dosent fix my problem
Posted: Fri Jul 21, 2006 3:23 pm
by Assured99
OK here is an update and i think this might help,
It seems that my script is trying to find a column in the database with the name of whatever i put in the company field.
any help anyone???
Posted: Fri Jul 21, 2006 3:38 pm
by Luke
try doing a full insert
for example:
Code: Select all
INSERT INTO `table` ( `id` , `username` , `password` , `name` , `email` , `phone_am` , `phone_pm` , `address` , `created` , `modified` )
VALUES (
NULL , '1234', '1234', '1234', '1234', '1234', '1234', '1234', '1234', '1234'
);
Posted: Fri Jul 21, 2006 3:39 pm
by Assured99
Call me a Noob but how do i do a full insert do i create that script????
Posted: Fri Jul 21, 2006 3:42 pm
by Luke
Code: Select all
// List the mysql table column names before the values like this...
$sql = "INSERT INTO $table_name ('firstname', 'lastname', 'company', 'username', 'password', 'users', '?', '?', 'pchange', 'email', 'access', 'url', 'verify', '?') VALUES
('$_POST[firstname]', '$_POST[lastname]', $_POST[company], '$_POST[username]', password('$_POST[password]'), 'Users', '', '', '$pchange',
'$_POST[email]', $_POST[access], '$default_url', '$verify', '')";
Posted: Fri Jul 21, 2006 3:49 pm
by Assured99
ok i did that with this
Code: Select all
$sql = "INSERT INTO $table_name ('firstname', 'lastname', 'company', 'username', 'password', 'group1', 'group2', 'group3', 'pchange', 'email', 'access', 'redirect', 'verified', 'last_login') VALUES
('$_POST[firstname]', '$_POST[lastname]', $_POST[company], '$_POST[username]', password('$_POST[password]'), 'Users', '', '', '$pchange',
'$_POST[email]', $_POST[access], '$default_url', '$verify', '')";
Which Coresponds exactly the feild names say in phpMyAdmin
and i get this error
Code: Select all
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 ''firstname', 'lastname', 'company', 'username', 'password', 'group1', 'group2', ' at line 1
Posted: Fri Jul 21, 2006 3:53 pm
by Da P3s7
space goat didn't you say that array values need to be quoted?
You wrote the code without quotes....
(just a hint??)
Edit to goat's edit: Soz then...

Posted: Fri Jul 21, 2006 3:54 pm
by Luke
Code: Select all
$sql = "INSERT INTO `$table_name` ('firstname', 'lastname', 'company', 'username', 'password', 'group1', 'group2', 'group3', 'pchange', 'email', 'access', 'redirect', 'verified', 'last_login') VALUES
($_POST['firstname'], $_POST['lastname'], $_POST['company'], $_POST['username'], password($_POST['password']), 'Users', '', '', $pchange,
$_POST['email'], $_POST['access'], $default_url, $verify, '')";
Try that... also... it's server homicide to put variables into your database directly from user's input. Sanitize first!!
Edit: It wasn't me that said that... but I just copied his code... didn't really look at that... fixed now!
Posted: Fri Jul 21, 2006 3:58 pm
by Assured99
Try that... also... it's server homicide to put variables into your database directly from user's input. Sanitize first!!
That makes sense but what do you mean by sanatizeing them
Also i think i found the problem im working on it now
Posted: Fri Jul 21, 2006 4:00 pm
by Da P3s7
possibly he means that you gotta clear out unwanted user input....like a slash that was entered there by mistake or not.
If you dont clean it you might get error from mysql.
Posted: Fri Jul 21, 2006 4:00 pm
by Luke
http://en.wikipedia.org/wiki/SQL_injection
Probably everything you need to know... (I just kinda skimmed through it)