
|
View Full Version : MySQL Insert
lilnomad 11-10-2006, 05:39 PM I hate to continually ask what I feel like are like repetitive questions but I cannot see anything wrong with this query I am trying to execute. If anyone would be so kind to help, I would really appreciate it.
Assume the variables are filled, and the column names are right, is there anything wrong with this:
$result = mysql_query("INSERT INTO users (group, user_name, password, first_name, last_name, gender, email_address) VALUES ('$group', '$user_name', '$password', '$first_name', '$last_name', '$gender', $email_address')");
Deltrumweb 11-10-2006, 05:50 PM Yes....
$email_address'
It must read '$email_address' with opening comma !
lilnomad 11-10-2006, 05:54 PM *kicks self for overlooking*... I made the change but still it wont execute.
Updated Query
$result = mysql_query("INSERT INTO users (group, user_name, password, first_name, last_name, gender, email_address) VALUES ('$group', '$user_name', '$password', '$first_name', '$last_name', '$gender', '$email_address')");
Deltrumweb 11-10-2006, 05:56 PM Sorry, I cannot see anything wrong with this query...maybe someone more versed at mysql queries can help....
horizon 11-10-2006, 05:56 PM If you post what this variable: $email_address is equal to, it might be possible to determine the cause of the problem. ;)
lilnomad 11-10-2006, 06:04 PM lilman[at]gmail[dot]com
acidhoss 11-10-2006, 06:08 PM I'm no PHP guru, but when variables are put into quotes, don't they become a literal string? example: when $email_address is put in quotes, instead of the value of $email_address being inserted, "$email_address" is inserted into the DB?
horizon 11-10-2006, 06:25 PM lilman[at]gmail[dot]com
Replace:
$email_address = "lilman[at]gmail[dot]com";
with:
$email_address = (stripslashes(trim("lilman@gmail.com")));
$replace_at_sign = (preg_match("/^.$/i", $email_address)) ? str_replace("@", "[at]", $email_address) : "";
$replace_dot_sign = (preg_match("/@/i", $email_address)) ? str_replace(".", "[dot]", $email_address) : "";
$check_sign_characters = (isset($replace_dot_sign) && isset($replace_at_sign)) ? $replace_at_sign.$replace_dot_sign : "";
Then, from your SQL statement, replace your $email_address variable with $check_sign_characters. Then, remove the quotes from that variable. No need to use them in those cases. ;)
lilnomad 11-10-2006, 06:48 PM I guess I didn't get what you were asking for, the $email_address is the value of $_POST["email_address"] but I did what you suggested and still it will not execute the query.
horizon 11-10-2006, 08:06 PM That's what I asked for - the first time actually. ;)
After replacing the above,
replace that line:
$email_address = (stripslashes(trim("lilman@gmail.com")));
with:
$email_address = (isset($_POST['email_address'])) ? (stripslashes(trim($_POST['email_address']))) : "";
lilnomad 11-10-2006, 09:00 PM Tried it but it still will not execute.
lilnomad 11-10-2006, 09:05 PM Here is the entire code, maybe it is something other than mysql_query()
$group = $_POST['group'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$user_name = $_POST['user_name'];
$email_address = (isset($_POST['email_address'])) ? (stripslashes(trim($_POST['email_address']))) : "";
$password = $_POST['password'];
$password2 = $_POST['password2'];
$gender = $_POST['gender'];
if(mysql_query("INSERT INTO users (group, user_name, password, first_name, last_name, gender, email_address) VALUES (".$group.", ".$user_name.", ".$password.", ".$first_name.", ".$last_name.", ".$gender.", ".$email_address.")"))
echo "successful in registering you an account";
else
{
echo "couldn't insert";
}
azizny 11-10-2006, 10:48 PM $result = mysql_query("INSERT INTO users (group, user_name, password, first_name, last_name, gender, email_address) VALUES ('$group', '$user_name', '$password', '$first_name', '$last_name', '$gender', '$email_address')") or $error = mysql_error();
if($error != NULL){echo "Error: $error";}
Give us the error.
Peace,
lilnomad 11-11-2006, 02:04 AM I figured out the problem. There is a keyword in MySQL group which was causing problems for me because I named a column group. Problem resolved. Thanks for the help
|