Sunday, 18 August 2013

PHP script not adding rows in MySQL database

PHP script not adding rows in MySQL database

I'm currently working on my website's login/register page but the issue
I'm having is that the PHP script isn't adding rows into the database.
I've been trying to figure this problem out for a few days but I haven't
come up with a solution. There are no errors present on the page upon
submission either...
<?php
mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());
if(isset($_POST['f_name']) && !empty($_POST['f_name']) &&
isset($_POST['l_name']) && !empty($_POST['l_name']) &&
isset($_POST['reg_email']) && !empty($_POST['reg_email']) &&
isset($_POST['conf_email']) && !empty($_POST['conf_email']) &&
isset($_POST['password']) && !empty($_POST['password']) &&
$_POST['birthday-day'] != 0 &&
$_POST['birthday-month'] != 0 &&
$_POST['birthday-year'] != 0)
{
$f_name = mysql_real_escape_string($_POST['f_name']);
$l_name = mysql_real_escape_string($_POST['l_name']);
$reg_email = mysql_real_escape_string($_POST['reg_email']);
$conf_email = mysql_real_escape_string($_POST['conf_email']);
$password = mysql_real_escape_string($_POST['password']);
$b_day = $_POST['birthday-day'];
$b_month = $_POST['birthday-month'];
$b_year = $_POST['birthday-year'];
$search = mysql_query("SELECT email FROM users WHERE
email='".$reg_email."'");
$match = mysql_num_rows($search);
if($reg_email !== $conf_email) {
$msg = "The emails dont match.";
}
if
(!preg_match("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$^",
$reg_email)) {
$msg = "The email you have entered is invalid. Please try again.";
}
if ($match > 0) {
$msg = "Email address already registered. Please enter a different
one.";
} else {
mysql_query("INSERT INTO userstest (f_name, l_name, email,
password) VALUES(
'".$f_name."',
'".$l_name."',
'".$reg_email."',
'".$password."') ") or die(mysql_error());
}
}
else {
//code
}
It may be a simple syntax error I'm not seeing but I appreciate any help I
get.

No comments:

Post a Comment