Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 233
  • Last Modified:

i have a problem in inserting table

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
mgtm3
Asked:
mgtm3
  • 3
  • 2
  • 2
1 Solution
 
glcumminsCommented:
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
 
mgtm3Author Commented:

<?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
 
fiboCommented:
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
fiboCommented:
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
 
glcumminsCommented:
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
 
mgtm3Author Commented:
problem fiexd thanks
0
 
fiboCommented:
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now