Jump to content

Adding new selection to Php/SQL code


Html

Recommended Posts

Hi,

While this code worked until now, I've added a new database field, so email. When I try that out, it gives an error, like as stated in the code, in the database I added email. But as for what it should be registered as in the properties, I don't know.

Thank you.

 

<?php
require 'connect.inc.php';

if (isset($_POST['fname']) and isset($_POST['lname']) and isset($_POST['uname']) and isset($_POST['email']) and isset($_POST['pwd']) and isset($_POST['pwd2']) 
	and !empty($_POST['fname']) and !empty($_POST['lname']) and !empty($_POST['uname']) and !empty($_POST['email']) and !empty($_POST['pwd']) and !empty($_POST['pwd2'])) {

$fname = mysqli_real_escape_string($conn, $_POST['fname']);
$lname = mysqli_real_escape_string($conn, $_POST['lname']);
$uname = mysqli_real_escape_string($conn, $_POST['uname']);
$email = mysqli_real_escape_string($conn, $_POST['email']);
$pwd = $_POST['pwd'];
$pwd2 = $_POST['pwd2'];

//The mysqli_real_escape_string prevents sql injection... We are hashing the passwords, so we don't need to do it on those lines.

/*This line checks to make sure the passwords match*/if ($pwd != $pwd2) {

	echo 'The passwords you entered didn\'t match';
} else {

	$check = "SELECT * FROM users WHERE uname = '$uname'";
	$res = mysqli_query($conn, $check);
	/*This line checks to make sure the user exists*/if (mysqli_num_rows($res)>0) {
		echo 'That username is taken.';
	} else {

		

$sql = "INSERT INTO users (fname, lname, uname, email, pwd, ) VALUES ('$fname', '$lname', '$uname', '$email' '$pwd')";
if (!mysqli_query($conn, $sql)) {

echo 'Error!';

} else {
echo 'Account created! <br> Click <a href="index.php">Here</a> to login';
				
			}
		}
	}
}
?>

 

db.jpg

Link to comment
Share on other sites

The following SQL statement is in error

$sql = "INSERT INTO users (fname, lname, uname, email, pwd, ) VALUES ('$fname', '$lname', '$uname', '$email' '$pwd')";

You have a comma after the variable name pwd that does not belong, and you left out the necessary comma between the two variable values $email and $pwd.

Roddy

  • Thanks 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...