Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-25-2012, 02:45 AM   PM User | #1
itxtme
Regular Coder

 
Join Date: Jun 2009
Posts: 102
Thanks: 3
Thanked 16 Times in 16 Posts
itxtme is an unknown quantity at this point
Another Unknown column 'sex' in 'field list'

Hey guys,

This is driving me crazy. I am writing a loop that means the application is scalable. To do that I am making it so a loop will write the DB. I am getting an error below

PHP Code:
Unknown column 'sex' in 'field list' 
The loop that creates the query is
PHP Code:
<?php // START UPDATE FORM
//Get the fields to update via query
$all_output1=""//set variable so it doesnt force "NOTICE" in loop
$all_output2=""//set variable so it doesnt force "NOTICE" in loop
if (isset($_POST['submit'])) {

    
$result mysql_query("SELECT field_name FROM child_fields WHERE editible='1'") or die(mysql_error());

        while(
$row mysql_fetch_array($result)){

           
$safe_variable make_safe($_POST[$row['field_name']]);
           
// Check for null
           
if (empty($safe_variable)) {
           
$output1 $row['field_name'].", ";
                         
$output2 "'', ";
           } else {
           
$output1 $row['field_name'].", ";
           
$output2 "'".$safe_variable."', ";
           }
           
           
$all_output1 .= $output1;
           
$all_output2 .= $output2;           
           

        }
        
//trim last comma and space        
        
$all_output1 substr($all_output1,0,-2);
        
$all_output2 substr($all_output2,0,-2);
        
        echo 
$all_output1."<br>".$all_output2;
I have added the echo to view the output of each, and that looks correct

PHP Code:
first_namelast_namedobsexethnicityschool, class, medicaldoctordoctor_practicedoctors_phoneswim_ability
'''''''female''''''122''Peanuts''''''''' 
The fields are null due to testing what will happen if the user doesnt enter information, I want the program to continue not have an sql error.

'sex' is definitely a column. The actual sql query is

Code:
  $query = "INSERT INTO caregiver ($all_output1) VALUES ($all_output2)";
I am lost as it appears from the echo that if I place that code in "()" as I have for the query it should run!? Any ideas people?? PS Have tried pasting the code into brackets straight into phpmyadmin and it works!?

Last edited by itxtme; 06-25-2012 at 02:56 AM..
itxtme is offline   Reply With Quote
Old 06-25-2012, 03:59 AM   PM User | #2
itxtme
Regular Coder

 
Join Date: Jun 2009
Posts: 102
Thanks: 3
Thanked 16 Times in 16 Posts
itxtme is an unknown quantity at this point
I am a retard -> had called the wrong table. So the error was quite correct, those columns did not exist!
itxtme is offline   Reply With Quote
Old 06-25-2012, 04:04 AM   PM User | #3
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,168
Thanks: 59
Thanked 3,993 Times in 3,962 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
First of all, do the obvious:
Code:
echo "<hr/>DEBUG query: " . $query . "<hr/>\n";
What does that show you? Is it what you expect?

Then if it is, make sure that you are right about that field existing in the table.

Try a query such as
Code:
DESCRIBE caregiver;
either in phpmyadmin or in a mysql command line.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 06-25-2012, 04:05 AM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,168
Thanks: 59
Thanked 3,993 Times in 3,962 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
LOL! Took me too long to answer you. AH, well. There is always next time.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 06-25-2012, 05:00 AM   PM User | #5
guelphdad
Super Moderator


 
guelphdad's Avatar
 
Join Date: Mar 2006
Location: St. Catharines, Ontario Canada
Posts: 2,629
Thanks: 4
Thanked 147 Times in 138 Posts
guelphdad will become famous soon enoughguelphdad will become famous soon enough
By the way an empty string and NULL are not the same thing at all as far as databases are concerned. Just be sure you understand that as if you test for IS NULL you'd have fields that had an empty string in them returned in a database query.
guelphdad is offline   Reply With Quote
Old 06-25-2012, 10:27 PM   PM User | #6
itxtme
Regular Coder

 
Join Date: Jun 2009
Posts: 102
Thanks: 3
Thanked 16 Times in 16 Posts
itxtme is an unknown quantity at this point
Thanks guys,

@ guelphdad

I learnt that the hard way! It seems to happen a lot when your new - the hard way thing I mean!
itxtme is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:46 PM.


Advertisement
Log in to turn off these ads.