Jump to content

not sure why I get this error on form process page


webguync

Recommended Posts

The error is "Error: Duplicate entry '' for key 'usr'"

 

I don't have any fields with that name.

 

here is the process code.

 

<?php
$con = mysql_connect("localhost","uname","pw") or die('Could not connect: ' . mysql_error());
mysql_select_db("db") or die(mysql_error());

$FirstName=mysql_real_escape_string($_POST['FirstName']); //This value has to be the same as in the HTML form file
$LastName=mysql_real_escape_string($_POST['LastName']); //This value has to be the same as in the HTML form file
$UserName=mysql_real_escape_string($_POST['UserName']); //This value has to be the same as in the HTML form file
$Password= md5($_POST['Password']); //This value has to be the same as in the HTML form file
$email=mysql_real_escape_string($_POST['email']); //This value has to be the same as in the HTML form file
$Zip=mysql_real_escape_string($_POST['Zip']); //This value has to be the same as in the HTML form file
$Birthday=mysql_real_escape_string($_POST['Birthday']); //This value has to be the same as in the HTML form file
$Security=mysql_real_escape_string($_POST['Security']); //This value has to be the same as in the HTML form file
/*
*  Specify the field names that are in the form. This is meant 
*  for security so that someone can't send whatever they want 
*  to the form.
*/
$allowedFields = array(
'FirstName',
'LastName',
'UserName',
'Password',
'email',
'Birthday',
'Zip',
'Security',
);

// Specify the field names that you want to require...
$requiredFields = array(
'FirstName',
'LastName',
'UserName',
'Password',
'email',
'Birthday',
'Zip',
'Security',
);

$errors = array();
foreach($_POST AS $key => $value)
{
// first need to make sure this is an allowed field
if(in_array($key, $allowedFields))
{
	$$key = $value;

	// is this a required field?
	if(in_array($key, $requiredFields) && $value == '')	
	{
		$errors[] = "The field $key is required.";
	}
}	
}

// were there any errors?
if(count($errors) > 0)
{
$errorString = '<p>There was an error processing the form.</p>';
$errorString .= '<ul>';
foreach($errors as $error)
{
	$errorString .= "<li>$error</li>";
}
$errorString .= '</ul>';

// display the previous form
include 'index.php';
}
else
{


$sql="INSERT INTO Profile (`FirstName`,`LastName`,`Username`,`Password`,`email`,`Zip`,`Birthday`,`Security`) VALUES ('$FirstName','$LastName','$UserName','$Password','$email','$Zip','$Birthday','$Security')"; 
if (!mysql_query($sql,$con)) {
die('Error: ' . mysql_error());
}
//send email
mail('email@gmail.com','A profile has been submitted!',$FirstName.' has submitted their profile',$body);

// display the thank you page
header("Location: thanks.html");
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.