no need to check for duplication on insert

which part of this do i need to remove to stop it from checking for duplicate and simply inserting it?
i have tried and keep accidentally taking out an extra { or something

[php]// Validate username

if(empty(trim($_POST[“firstname”])))
{

$username_err = “Please enter a first name.”;

} else{

// Prepare a select statement

$sql = “SELECT firstname FROM managers WHERE firstname = ?”;

if($stmt = mysqli_prepare($link, $sql)){

// Bind variables to the prepared statement as parameters

mysqli_stmt_bind_param($stmt, “s”, $param_firstname);

// Set parameters

$param_firstname = trim($_POST[“firstname”]);

// Attempt to execute the prepared statement

if(mysqli_stmt_execute($stmt)){

/* store result */

mysqli_stmt_store_result($stmt);

if(mysqli_stmt_num_rows($stmt) == 1)
{

$username_err = “This first name is already taken.”;

} else{

$username = trim($_POST[“firstname”]);

}

} else{

echo “Oops! Something went wrong. Please try again later.”;

}

}

// Close statement
mysqli_stmt_close($stmt);

}[/php]

There is no check for duplicates here. Either it’s somewhere else or the column is set to unique in the db. Be aware though that if the application expects this to be unique then “interesting” things may happen if you ignore this

i have tried and keep accidentally taking out an extra { or something

If you want help with the version of code that you tried, you will need to post it. Not sure why you would have produced any program logic to test if a first name already exists, since your previous code wasn’t doing this for the first name.

Next, you need to reread the replies in one of your previous threads, about cleaning up your code. If your code only contains the necessary logic, you will be more likely to be able to successfully make changes to it.

thank you both

Sponsor our Newsletter | Privacy Policy | Terms of Service