Unknown column 'N' in 'field list'

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

User avatar
Assured99
Forum Commoner
Posts: 81
Joined: Wed Jul 12, 2006 11:48 am
Location: California

Unknown column 'N' in 'field list'

Post 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
User avatar
kbrown3074
Forum Contributor
Posts: 119
Joined: Thu Jul 20, 2006 1:36 pm

Post 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?
User avatar
Assured99
Forum Commoner
Posts: 81
Joined: Wed Jul 12, 2006 11:48 am
Location: California

Post by Assured99 »

Weirdan | Please use

Code: Select all

,

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

,

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]
Ward
Forum Commoner
Posts: 74
Joined: Thu Jul 13, 2006 10:01 am

Post 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.

Code: Select all

$_POST[firstname]
Should be

Code: Select all

$_POST["firstname"]
(double or single quotes are okay)
User avatar
Assured99
Forum Commoner
Posts: 81
Joined: Wed Jul 12, 2006 11:48 am
Location: California

Post by Assured99 »

But that still dosent fix my problem
User avatar
Assured99
Forum Commoner
Posts: 81
Joined: Wed Jul 12, 2006 11:48 am
Location: California

Post 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???
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post 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'
);
User avatar
Assured99
Forum Commoner
Posts: 81
Joined: Wed Jul 12, 2006 11:48 am
Location: California

Post by Assured99 »

Call me a Noob but how do i do a full insert do i create that script????
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post 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', '')";
User avatar
Assured99
Forum Commoner
Posts: 81
Joined: Wed Jul 12, 2006 11:48 am
Location: California

Post 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
User avatar
Da P3s7
Forum Commoner
Posts: 30
Joined: Wed Jul 19, 2006 3:25 pm
Location: /usr/src/kernels/ 2.6.15-1.2054_FC5-i686

Post by Da P3s7 »

space goat didn't you say that array values need to be quoted? :P
You wrote the code without quotes....
(just a hint??)

Edit to goat's edit: Soz then... :oops:
Last edited by Da P3s7 on Fri Jul 21, 2006 3:57 pm, edited 2 times in total.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post 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!
User avatar
Assured99
Forum Commoner
Posts: 81
Joined: Wed Jul 12, 2006 11:48 am
Location: California

Post 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
User avatar
Da P3s7
Forum Commoner
Posts: 30
Joined: Wed Jul 19, 2006 3:25 pm
Location: /usr/src/kernels/ 2.6.15-1.2054_FC5-i686

Post 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.
Last edited by Da P3s7 on Fri Jul 21, 2006 4:02 pm, edited 2 times in total.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

http://en.wikipedia.org/wiki/SQL_injection

Probably everything you need to know... (I just kinda skimmed through it)
Post Reply