Jump to content

MySQL error in PHP..."Unknown column 'test' in 'fieldlist'"


doogles

Recommended Posts

MySQL version 5.0.22

 

My problem is when I try to insert values based on user input into a table also based on user input.

 

The table is created fine. I verified it. It's the values I try to put it the table that don't go.

 

Here's the small script that adds the table:

 

$createtable="CREATE table $class (

title varchar (25),

points_earned varchar (4),

points_possible varchar (4))";

mysql_query($createtable);

 

Here's the script that adds the values:

 

if ($grade1 !=="") {$ins="insert into $class values($grade1, $g1e, $g1t)"; mysql_query($ins) or die(mysql_error());}

 

The error mysql gives depends on the user's value for $grade1. I've verified also that all the values I try to insert exsist by having the script print them to the browser. If $grade1 is 'test' then I get:

 

"Unknown column 'test' in 'fieldlist'"

 

Thanks!

 

 

Link to comment
Share on other sites

if you do not surround your insert values with quotes, MySQL will assume that you're referring to a column from a previous sub-query.  surrounding the values with single quotes will alleviate this issue:

 

$ins="insert into $class values('$grade1', '$g1e', '$g1t')";

 

it doesn't look like you're doing much/any validation on the user input.  HUGE security flaw.  proceed with caution.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.