Solved

i have a problem in inserting table

Posted on 2008-06-09
7
229 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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!

 
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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

734 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