Jump to content

I have a Duplicate Entry" for key 'name'


co.ador

Recommended Posts

 $sql = mysql_query("INSERT INTO products (name, price, details, category, subcategory,  category_id, city, state, country, date_added) 
VALUES('$tname','$price','$details','$category','$subcategory','$category_id','$city','$state','$country', now())") or die (mysql_error());
	// Get the inserted ID here to use in the activation email
	$id = mysql_insert_id();

 

That's the query where the problem seems to be happening.

 

 

Also I have a code above this query for validation purposes that goes like

 

if (isset($_POST['Insert'])){
//Connect to the database through our include 
include "storescripts/connect_to_mysql.php";
// Filter the posted variables
$name = ereg_replace("[^A-Za-z0-9]", "", $_POST['name']); // filter everything but numbers and letters
$country = ereg_replace("[^A-Z a-z0-9]", "", $_POST['country']); // filter everything but spaces, numbers, and letters
$state = ereg_replace("[^A-Z a-z0-9]", "", $_POST['state']); // filter everything but spaces, numbers, and letters
$city = ereg_replace("[^A-Z a-z0-9]", "", $_POST['city']); // filter everything but spaces, numbers, and letters
$price = $_POST['price'];
        $details = ereg_replace("[^A-Z a-z0-9]", "", $_POST['details']); // filter everything but spaces, numbers, and letters
        $category = $_POST['category']; 
       $subcategory = ereg_replace("[^A-Z a-z0-9]", "", $_POST['subcategory']); // filter everything but spaces, numbers, and letters
       $category_id = $_POST['category_id'];  
if((!$productname) || (!$country) || (!$state) || (!$city) || (!$price) || (!$details) || (!$subcategory))		{
	$errorMsg = "You did not submit the following required information!<br /><br />";
	if(!$name){
		$errorMsg .= "--- User Name";
	} else if(!$country){
		$errorMsg .= "--- Country"; 
	} else if(!$state){ 
	    $errorMsg .= "--- State"; 
   } else if(!$city){ 
       $errorMsg .= "--- City"; 
   } else if(!$price){ 
       $errorMsg .= "--- Price"; 
   } else if(!$details){ 
       $errorMsg .= "--- Details"; 
   } else if(!$subcategory){ 
       $errorMsg .= "--- Subcategory"; 
   }
   }	

} 
else { "fill the spaces in blank please...";}

 

Thank you.

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.