Solved

i have a problem in inserting table

Posted on 2008-06-09
7
224 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
Comment Utility
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
Comment Utility

<?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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 29

Expert Comment

by:fibo
Comment Utility
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
Comment Utility
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
Comment Utility
problem fiexd thanks
0
 
LVL 29

Expert Comment

by:fibo
Comment Utility
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

Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Build JSON from table records 17 38
Wordpress syntax error 1 27
session dropped in IE 10 18
uploading multiple image with php 14 15
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

763 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

6 Experts available now in Live!

Get 1:1 Help Now