PHP/MySQL - Update Database/Run PHP Script on Button Click

lauramanila

New Member
I have a 'registration' page in PHP and I would like the script to run when an HTML button is clicked.The PHP basically checks if all fields are filled, checks if the password and email confirmations are the same and saves to the database.This is the code:\[code\]<?php$Name = isset($_POST['Name']);$Surname = isset($_POST['Surname']);$Username = isset($_POST['Username']);$Email = isset($_POST['Email']);$C_Email = isset($_POST['C_Email']);$Password = isset($_POST['password']);$C_Password = isset($_POST['c_password']);$SecQ = isset($_POST['SecQ']);$SecA = isset($_POST['SecA']);$con = mysql_connect('localhost', 'admin', 'storefile1234');mysql_select_db ("storefile");$check_username = mysql_query("SELECT FROM users WHERE username = '$Username'");$check_email = mysql_query("SELECT FROM users WHERE Email = '$Email'");if (!$con) { die('Could not connect: ' . mysql_error()); }if ($Name == null || $Surname== null || $Username == null || $Password == null || $C_Password == null || $Email == null || $C_Email == null || $SecQ == null || $SecA == null ) { echo "Missing details. Please enter all fields.";} else { if(mysql_num_rows($check_username) != 0 && mysql_num_rows($check_email) != 0) { echo "Username/Email already exists"; } if ($Email == $C_Email && $Password == $C_Password) { $query = "INSERT INTO users (Username, Name,Surname, Password, Email, SecQ, SecA) VALUES ('NULL', ".$Username."', ".$Name."', ".$Surname."', ".$Password."', ".$SecQ."', ".$SecA."', ".$Email.')"'; mysql_query($query) or die ('Error registering.'); echo "Greetings, ".$Name.", you have been registered. "; } else { echo "Error registering your account. Please try again."; } }?>\[/code\]Also, is it recommended?Whenever I run this page \[code\]Missing details. Please enter all fields.\[/code\] displays, without having entered any details.How do you do this?
 
Top