Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jun 2009
    Posts
    144
    Thanks
    3
    Thanked 20 Times in 20 Posts

    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.

  • #2
    Regular Coder
    Join Date
    Jun 2009
    Posts
    144
    Thanks
    3
    Thanked 20 Times in 20 Posts
    I am a retard -> had called the wrong table. So the error was quite correct, those columns did not exist!

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,986
    Thanks
    79
    Thanked 4,432 Times in 4,397 Posts
    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.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,986
    Thanks
    79
    Thanked 4,432 Times in 4,397 Posts
    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.

  • #5
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,634
    Thanks
    4
    Thanked 148 Times in 139 Posts
    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.

  • #6
    Regular Coder
    Join Date
    Jun 2009
    Posts
    144
    Thanks
    3
    Thanked 20 Times in 20 Posts
    Thanks guys,

    @ guelphdad

    I learnt that the hard way! It seems to happen a lot when your new - the hard way thing I mean!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •