...

View Full Version : Resolved Unknown column 'greg' in 'field list'



slappyjaw
09-12-2009, 03:54 AM
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
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(25, 45);
//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");
}
}


?>

sea4me
09-12-2009, 04:13 AM
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

slappyjaw
09-12-2009, 04:20 AM
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'

CFMaBiSmAd
09-12-2009, 04:25 AM
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.

sea4me
09-12-2009, 04:26 AM
I see what's wrong, your missing ' single quotes around the values that aren't numbers....

Should be this:

$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."')";

CFMaBiSmAD snuck in there :P

slappyjaw
09-12-2009, 04:38 AM
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!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum