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 slappyjaw's Avatar
    Join Date
    Mar 2009
    Location
    Wonderland!
    Posts
    146
    Thanks
    14
    Thanked 3 Times in 3 Posts

    Question Unknown column 'greg' in 'field list'

    I keep getting the error Unknown column 'Greg' in field list. The name greg is a posted variable. I have tried google many times and cant find a solution that seems to work for this. Thank you for all your help.
    PHP Code:
    <?php
    if (isset($_POST['submit'])){
    //START INSERT TRANSACTION
    //inlcude the database connection header!
    include("Connections/db_connect_inf.php");
    // Connect to server and select databse.
    mysql_connect("$host""$username""$password")or die("cannot connect to mysql database!");
    mysql_select_db("$db_name")or die("cannot select DB");

    // To protect MySQL injection (more detail about MySQL injection)
    $slappyjaw_username mysql_real_escape_string($_POST['register_username']);
    $slappyjaw_password mysql_real_escape_string($_POST['register_password']);
    $slappyjaw_email mysql_real_escape_string($_POST['register_email']);
    $slappyjaw_securityquestion mysql_real_escape_string($_POST['register_security_question']);
    $slappyjaw_securityanswer mysql_real_escape_string($_POST['register_security_answer']);
    $slappyjaw_provider mysql_real_escape_string($_POST['register_cell_provider']);
    $slappyjaw_cellnumber mysql_real_escape_string($_POST['register_cell_number']);
    $slappyjaw_firstname mysql_real_escape_string($_POST['register_firstname']);
    $slappyjaw_lastname mysql_real_escape_string($_POST['register_lastname']);
    $slappyjaw_randomkey rand(2545);
    //MD5 encrypt username for the login
    $slappyjaw_register_password_encrypted md5($slappyjaw_password);
    //Find the information for the user based on thier login information.

    $sql="INSERT INTO users (users_firstname, users_lastname, users_username, users_password, users_email, users_cellnumber, users_provider, users_securityquestion, users_securityanswer, users_randomkey) VALUES (".$slappyjaw_firstname.", ".$slappyjaw_lastname.", ".$slappyjaw_username.", ".$slappyjaw_register_password_encrypted.", ".$slappyjaw_email.", ".$slappyjaw_cellnumber.", ".$slappyjaw_provider.", ".$slappyjaw_securityquestion.", ".$slappyjaw_securityanswer.", ".$slappyjaw_randomkey.")";
    $result mysql_query($sql) or die(mysql_error());
    header("location:login.php?action=register");
    }
    }


    ?>
    Last edited by slappyjaw; 09-12-2009 at 04:38 AM.

  • #2
    Regular Coder sea4me's Avatar
    Join Date
    Jan 2009
    Location
    Damn, I don't know...
    Posts
    390
    Thanks
    11
    Thanked 28 Times in 27 Posts
    that usually means that your inserting something into the field "greg" when it should be the values...

    echo out your $sql and post it here

  • #3
    Regular Coder slappyjaw's Avatar
    Join Date
    Mar 2009
    Location
    Wonderland!
    Posts
    146
    Thanks
    14
    Thanked 3 Times in 3 Posts
    INSERT INTO users (users_firstname, users_lastname, users_username, users_password, users_email, users_cellnumber, users_provider, users_securityquestion, users_securityanswer, users_randomkey) VALUES (Gregory, Jordan, slapp, 32030ef34d2892af760feb66168b643c, text, 55555555555, vtext, iijijijijij, jijijijij, 1054452581)

    Error Unknown column 'Gregory' in 'field list'

  • #4
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    2,958
    Thanks
    2
    Thanked 304 Times in 296 Posts
    String data must be enclosed in single-quotes to them it a string. Otherwise it is treated as an identifier (column, table, or database name...) Put single-quotes around each value in the query.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #5
    Regular Coder sea4me's Avatar
    Join Date
    Jan 2009
    Location
    Damn, I don't know...
    Posts
    390
    Thanks
    11
    Thanked 28 Times in 27 Posts
    I see what's wrong, your missing ' single quotes around the values that aren't numbers....

    Should be this:
    PHP Code:
    $sql="INSERT INTO users (users_firstname, users_lastname, users_username, users_password, users_email, users_cellnumber, users_provider, users_securityquestion, users_securityanswer, users_randomkey) VALUES ('".$slappyjaw_firstname."', '".$slappyjaw_lastname."', '".$slappyjaw_username."', '".$slappyjaw_register_password_encrypted."', '".$slappyjaw_email."', '".$slappyjaw_cellnumber."', '".$slappyjaw_provider."', '".$slappyjaw_securityquestion."', ".$slappyjaw_securityanswer."', '".$slappyjaw_randomkey."')"
    Edit: CFMaBiSmAD snuck in there :P

  • #6
    Regular Coder slappyjaw's Avatar
    Join Date
    Mar 2009
    Location
    Wonderland!
    Posts
    146
    Thanks
    14
    Thanked 3 Times in 3 Posts
    Wow thats awsome thank you both so much. Ugh i need to remember that, i thought that you didnt have to do that in php i thought that it was slightly different than in the actual mysql admin area. thank you all!


  •  

    Posting Permissions

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