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!

 

 

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.