But mine is not storing and also it shows this message even if I enter all required fields. Here is my code:
***** Please use the
Code: Select all
tag when posting code *****[/color]Code: Select all
<?php
$db = mysql_connect(localhost, 'db_username', 'db_password') or die('Error: ' . mysql_error());
mysql_select_db('dbname') or die('Could not select database');
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$username = $_POST['username'];
$password = $_POST['passowrd'];
$str = $_POST['street'];
$city = $_POST['city'];
$state = $_POST['state'];
$zipcode = $_POST['zipcode'];
$phone = $_POST['phone'];
$email = $_POST['email'];
if ((!empty($_POST['firstname'])) && (!empty($_POST['lastname']))){
$firstname = "firstname; $_POST[firstname]";
$lastname = "lastname; $_POST[lastname]";
}else {
echo "Please enter your firstname and lastname in the fields provided<br/>";
}
if((!empty($_POST['username'])) && ((!strlen($_POST['username'] < 6)) && (!strlen($_POST['username'] > 32)))){
$sql = "SELECT * FROM Accounts WHERE Username='$username'";
$query = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($query) < 1)
{$username = "username; $_POST[username]";
}else{
$username = NULL;
echo "Username already exists. Please enter a different username.<br/>";
}
}
if((!empty($_POST['password'])) && ((!strlen($_POST['password'] < 6)) && (!strlen($_POST['password'] > 32)))){
$password = "password; $_POST[password]";
}else{
$password = NULL;
echo "Please enter a valid alphanumeric password that is atleast 6 characters long.<br/>";
}
if(!empty($_POST['street'])){
$str = "street; $_POST[street]";
}else{
$str= NULL;
echo "Please enter a valid Street name.<br/>";
}
if(!empty($_POST['city'])){
$city = "City; $_POST[city]";
}else{
$city = NULL;
echo "Please enter a valid City name.<br/>";
}
if(!empty($_POST['state'])){
$state = "State; $_POST[State]";
}else{
$state = NULL;
echo "Please select a state from the drop down menu name.<br/>";
}
if (preg_match("/^[0-9]{5}([0-9]{4})?$/i", $zipcode)) {
$zipcode = "zipcode; $_POST[zipcode]";
} else {
$zipcode = NULL;
echo "Zip Code is invalid.<br/>";
}
if (preg_match("/^[2-9]{1}[0-9]{2}-[0-9]{3}-[0-9]{4}?$/i", $phone)) {
$phone = "phone; $_POST[phone]";
} else {
$phone = NULL;
echo "Please enter a valid phone number.<br/>";
}
if(preg_match("/^[^0-9][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[@][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[.][a-zA-Z]{2,4}?$/i",$email)){
$email = "email; $_POST[email]";
} else {
$email = NULL;
echo "Please enter a valid E-Mail address.<br/>";
}
mysql_query("INSERT INTO Accounts (Firstname, Lastname, Username, Password, Street, City, State, Zipcode, Primary Phone, Email) VALUES ('$firstname', '$lastname', '$username', '$password', '$str', '$city', '$state', '$zipcode', '$phone', '$email'))");
?>Please enter a valid alphanumeric password that is atleast 6 characters long.
Please enter a valid Street name.
Please enter a valid City name.
Please select a state from the drop down menu name.
Thank you so much.
Priya