PHP Form Validator/MySQL Insert

erobrebop

New Member
I have written a small PHP file that gets the information that was posted to it, then checks to make sure it is no empty. If it isn't empty, it checks to make sure the username doesn't already exist. If it does, it redirects. If not, it adds the information to the MySQL database. I don't know what the problem is, but when attempting to navigate to it after pressing the submit button on the form, the browser displays an error saying that the page cannot be displayed. Here is the code.\[code\]<?php$firstname = $_POST['fname'];$lastname = $_POST['lname'];$email = $_POST['email'];$username = $_POST['user'];$password = $_POST['pass'];$con = mysql_connect("localhost","USER","PASS");if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("zach_blogin", $con);$query="SELECT username FROM members WHERE username=$username";if (mysql_num_rows($username) > 0 ) { header("Location: register.php?invalid");} else { $sql=("INSERT INTO members (username, password, FirstName, LastName, Email) VALUES ($username, $password, $firstname, $lastname, $email)"); if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); }else { header("Location: register.php?required");}?>\[/code\]
 
Back
Top