I have built a simple registration form shown below and Iam trying to get the users to have their passwords encrypted and then entered into my database. I am attempting to use md5 encryption. I have also attached the database connection script.
My goal is when I check my database, I want to see the following: ( id, name, username, encrypted password )
The issue I have is that the form does not process completely. All I get this error (Error: Unknown column 'd8578edf8458ce06fbc5bb76a58c5ca4' in 'field list' ).
Could some tell me or show me " What is it that needs to be corrected either in my Code or SQL insert and /or my Variables" to make this work correctly. I know that its probably a very, very simple fix. I am just stuck at this point.
I really appreciate your help.
<?php
error_reporting(0);
if($_POST['submit'])
{ //Begining of full IF Statment
$name = $_POST['name'];
$username = $_POST['username'];
$password = $_POST['password'];
$confirm_password = $_POST['confirm_password'];
// Encrypt Pasword
$enc_password = md5($password);
//$enc_password2 = md5($confirm_password);
// Confirm All feild were filled out when submit button was pressed
if($name && $username && $password && $confirm_password)
{
// Confirm that the NAME that you used is NOT greater than 30 characters
if(strlen($name)>24)
{
echo "<h2><center>YOUR NAME IS TOO LONG!!!!</center></h2><br>";
}
// Confirm that the USERNAME that you used is NOT greater than 10 characters
if(strlen($username)>10)
{
echo "<h2><center>YOUR USERNAME IS TOO LONG!!!!</center></h2><br>";
}
else {
// Confirm that the PASSWORD that you used MATCH & Between 6 and 15 characters
if(strlen($password)>10 || strlen($password)<6)
{
echo "<h2><center>YOUR PASSWORD MUST BE BETWEEN 6 and 15 CHARACTERS!!!!</center></h2><br>";
}
if($password == $confirm_password)
{
// Database Connection required
require "db_conncect.php";
// We Now connect to the Dabase and insert the Form input details
//------- ### ENTERING ALL INFORMATION INTO THE DATABASE BELOW ### --------//
// 1. Create a database connection
$con = mysql_connect("localhost","root",""); // <-- THIS IS WHERE YOU " CAN CHANGE " THE USERNAME IS "root", PASSWORD IS "" ONLY.
if (!$con) {
die('Database connection failed could not connect: ' . mysql_error());
}
// 2. Select a database to use
$db_select = mysql_select_db("registernow_2012",$con); // <-- THE "registernow_2012" IS THE NAME OF THE DATABASE.
if (!$db_select) {
die('Database selection failed could not connect: ' . mysql_error());
}
mysql_select_db("registernow_2012", $con); // <-- THE "registernow_2012" IS THE NAME OF THE DATABASE TO BE CONNECTED.
// <-- THE `registernow_2012` IS THE NAME OF THE DATABASE TO BE CONNECTED.... `visitors` IS THE TABLE WITH ALL THE FIELDS WITHI IN THE DATABASE.
$sql="INSERT INTO `registernow_2012`.`users` (`id` , `name` , `username` ,
`$enc_password` , `confirm_password` )
VALUES (NULL , '$_POST[name]', '$_POST[username]', '[$enc_password]', '$_POST[confirm_password]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
// 3. Close Connection
mysql_close($con);
header("Location: index.php"); // <-- THIS IS WHERE YOU CAN CHANGE THE "Location: Thank you / Index page" of the THANK YOU PAGE.
}
else
{
echo "<h2><center>PASSWORDS MUST MATCH!!!!!</center></h2><br>";
}
}
//echo "<h2><center>WORKING!!!!</center></h2>";
}
else echo "<h2><center>ALL FEILDS MUST BE COMPLETED</center></h2>";
} //Ending of full IF Statment
?>
<!DOCTYPE html>
<html lang='en'>
<head>
<title>THE FORM MY WAY NOW</title>
</head>
<body>
<div id='centerstage'>
<form name="myform" action="workingitoutproperly.php" method="POST">
<p>
<label>Name</label><br>
<input type='text' name='name' value=''><br>
<label>UserName</label><br>
<input type='text' name='username' value=''><br>
<label>Password</label><br>
<input type='password' name='password' value=''><br>
<label>Re-Enter Password</label><br>
<input type='password' name='confirm_password' value=''><br>
<br>
<input type='submit' name='submit' value='REGISTER NOW!!'>
</p>
</form>
</div>
</body>