Solved

i have a problem in inserting table

Posted on 2008-06-09
7
226 Views
Last Modified: 2010-04-21
o.k i am tring to to this code and i get this problem

Unknown column 'gfdg' in 'field list'      


but the problem that i did not try to insert in a field named gfdg so why is that happning?
$f = "INSERT INTO poll3 (op1,op2,op3,op4,op5,subject,gen) VALUES ($op1,$op2,$op3,$op4,$op5,$subject,$gen)";
mysqli_query($link,$f);
 
echo mysqli_error($link);

Open in new window

0
Comment
Question by:mgtm3
  • 3
  • 2
  • 2
7 Comments
 
LVL 24

Expert Comment

by:glcummins
ID: 21745241
Can you post more complete code than this? The error is not based on the query that you provided to us. Perhaps something else is changing the $f variable before you run the query?
0
 

Author Comment

by:mgtm3
ID: 21745249

<?php
 
include 'cpoll.php';
 
 
$subject = $_POST['subject'];
$op1 = $_POST['op1'];
$op2 = $_POST['op2'];
$op3 = $_POST['op3'];
$op4 = $_POST['op4'];
$op5 = $_POST['op5'];
$gen=$_POST['gen'];
 
 
$sql = 'CREATE TABLE `poll3` (
`id` int( 255 ) NOT NULL AUTO_INCREMENT,
  `subject` VARCHAR( 700 )NOT NULL,
        `op1` VARCHAR( 700 )NOT NULL,
        `op2` VARCHAR( 700 ) NOT NULL,
        `op3` VARCHAR( 700 ) NOT NULL,
        `op4` VARCHAR( 700 ) NOT NULL,
        `op5` VARCHAR( 700 ) NOT NULL,
		`date` VARCHAR( 700 ) NOT NULL,
		`user` VARCHAR( 700 ) NOT NULL,
		`gen` VARCHAR( 700 ) NOT NULL,
		
        PRIMARY  KEY ( `id` )
       )';
 
 
mysqli_query($link,$sql);
 
mysqli_close($link);
unset($link);
include 'cpoll.php';
 
$f = "INSERT INTO poll3 (op1,op2,op3,op4,op5,subject,gen) VALUES ($op1,$op2,$op3,$op4,$op5,$subject,$gen)";
mysqli_query($link,$f);
 
echo mysqli_error($link);

Open in new window

0
 
LVL 29

Accepted Solution

by:
fibo earned 500 total points
ID: 21745252
I would prefer
 $f = "INSERT INTO poll3 (op1,op2,op3,op4,op5,subject,gen)
   VALUES ('$op1','$op2','$op3','$op4','$op5','$subject','$gen')";

and you need to test first without any ' in your data. once this work... you will have to check what happens with ' in data (maqic-quotes...)
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 29

Expert Comment

by:fibo
ID: 21745293
Note: you define date and user as not null, while your insert does not provide data for them...
Note 2: at line 33 you close the connection, which your line 38 assumes to be open. was it opened in the second copy of cpoll.php that you include at line 35?
0
 
LVL 24

Expert Comment

by:glcummins
ID: 21745307
I will second fibo's comment that you need single quotes around each of the pieces of data. In general, you will want to put backticks around each of the field names so that they do not interfere with MySQL reserved words.

$f = "INSERT INTO poll3 (`op1`,`op2`,`op3`,`op4`,`op5`,`subject`,`gen`) VALUES ('$op1','$op2','$op3','$op4','$op5','$subject','$gen')";

Also, on a note unrelated to your original problem, you will want to change your CREATE TABLE query to:

 $sql = 'CREATE TABLE IF NOT EXISTS `poll3` (

This will help you to avoid problems if the table has already been created.
0
 

Author Closing Comment

by:mgtm3
ID: 31465487
problem fiexd thanks
0
 
LVL 29

Expert Comment

by:fibo
ID: 21745477
Thx for the points.
And I also support glcummins' suggestions. "Defensive programming" does not take a lot more time when writing the programs... but saves lots of debugging time now and in some time from noiw, when your program will move to a different server!
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
php extract($_REQUEST) 5 43
000webhost.com default error log 1 23
comma true 6 31
Cookie not unsetting 7 18
This article discusses four methods for overlaying images in a container on a web page
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now