Please i need help on the code i have posted below. I am supposed to validate the form before posting the data into the database. When i run the code on my computer it is submiting all the data into the database, but the password is not submited and before submiting the data for any missing fields the user must be notified. That is what i am trying to do with the if statements. Pleae help its urgent
Code:
<html> <head> <title>Insert players</title> <?PHP //Declaring the valriable that will be used to process the form $full_name = ''; $surname = ''; $contact_number = ''; $email = ''; $position = ''; $username = ''; $password = ''; //These variables will hold error messages $error_message = ''; $name_error = ""; $surname_error = ""; $contact_number_error = ""; $email_error = ""; $position_error = ""; $username_error = ""; $password_error = ""; if (isset($_POST['Submit1'])) { //Validating input data if($full_name == "") { $name_message = $name_message. "You did not enter the name"; } if($full_name_length <=50) { $full_name_length = ""; } else { $full_name_length = $full_name_length. "The name muust not exceed 50 characters, and cannot be left empty"; } if($surname == "") { $surname = $surname. "You did not enter the surname"; } if($surname_length <=50) { $surname_length = ""; } else { $surname_length = $surname_length. "The surname must not exceed 50 characters, and cannot be left empty"; } else { //Posting the data entered using the POST method $full_name = $_POST['name']; $surname = $_POST['surname']; $contact_number = $_POST['contact_number']; $email = $_POST['email']; $position = $_POST['position']; $username = $_POST['username']; $password = $_POST['password']; //Convert first letter of each word to capital letters $full_name = ucwords($full_name); $surname = ucwords($surname); $position = ucwords($position); $username = ucwords($username); //Checking how many characters a string contains $full_name_length = strlen($full_name); $surname_length = strlen($surname); $contact_number_length = strlen($contact_number); $position_length = strlen($position); $username_length = strlen($username); $password_length = strlen($password); //Connecting to the database $user_name = "root"; $password = ""; $database = "zebrascricketclub"; $server = "127.0.0.1"; $db_handle = mysql_connect($server, $user_name, $password); $db_found = mysql_select_db($database, $db_handle); if($db_found) { $query = "INSERT INTO players (name,surname,contact_number,email,position,username,password) VALUES ('$full_name','$surname','$contact_number','$email','$position','$username','$password')"; $result = mysql_query($query); mysql_close($db_handle); header("Location: success_insert.php"); } else { echo "Data could not be submitted"; mysql_close($db_handle); } } } ?> </head> <body> <center><h2>Insert players in the form below</h2></center> <center><?php echo $name_error; ?></center> <center><?php echo $surname_error; ?></center> <center><FORM NAME ="form1" METHOD ="POST" ACTION ="insert.php"> Name: <input type = 'text' name ='name' value="<?PHP print $full_name; ?>" ><br> <br> Surname: <input type = 'text' name = 'surname' value = "<?php echo $surname; ?>" ><br> <br> Contact number: <input type = 'text' name = 'contact_number' value = "<?php echo $contact_number; ?>"> <br> <br> Email: <input type = 'text' name = 'email' value = "<?php echo $email; ?>"><br> <br> Position: <input type = 'text' name = 'position' value = "<?php echo $position; ?>"><br> <br> Username: <input type = 'text' name = 'username' value = "<?php echo $username; ?>"> <br> <br> Password: <input type = 'password' name = 'password' value = "<?php echo $password; ?>"><br> <br> <input type = "Submit" name = "Submit1" VALUE = "Submit"></center> </FORM> </body> </html>
Comment