doogles Posted June 6, 2007 Share Posted June 6, 2007 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! Quote Link to comment https://forums.phpfreaks.com/topic/54490-mysql-error-in-phpunknown-column-test-in-fieldlist/ Share on other sites More sharing options...
akitchin Posted June 6, 2007 Share Posted June 6, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/54490-mysql-error-in-phpunknown-column-test-in-fieldlist/#findComment-269519 Share on other sites More sharing options...
doogles Posted June 6, 2007 Author Share Posted June 6, 2007 oh, its just on my localhost. I'm not putting this on my site. And thanks! I'll see what that does. Quote Link to comment https://forums.phpfreaks.com/topic/54490-mysql-error-in-phpunknown-column-test-in-fieldlist/#findComment-269520 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.