Hello all,
I have an question, I have PHP code to create a unique ID but I want to be sure it is unique. If not it has to do an action: create a new ID that is not exists already.
This is my code:
<?php
function random_strings($length_of_string)
{
$str_result = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
return substr(str_shuffle($str_result), 0, $length_of_string);
}
ob_start();
echo random_strings(10);
$Output = ob_get_contents();
ob_end_clean();
$conn = mysqli_connect("localhost", "probleem_uniqid", "Password", "DBname");
if($conn === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
$Name = $_POST['Name'];
$Email = $_POST['Email'];
$Phone = $_POST['Phone'];
$Problem = $_POST['Problem'];
if ($stmt = mysqli_prepare($conn, "INSERT INTO ID (Id, Name, Email, Phone, Problem) VALUES (?, ?, ?, ?, ?)")) {
mysqli_stmt_bind_param($stmt, "sssss", $Output, $Name, $Email, $Phone, $Problem);
if (mysqli_stmt_execute($stmt)) {
echo ' ';
echo "<div id=\"PHP-output\"> Succesvol Verstuurd </div>";
} else{
echo ' ';
echo "<div id=\"PHP-output\"> Sorry, Het kon niet worden verstuurd, probeer het later nog eens of neem contact op met de klantenservice. $sql. </div>" . mysqli_error($conn);
}
}
mysqli_close($conn);
?>
What I have tried:
I don't know very much about PHP, but I tried to follow yt tutorials or web tutorials but I can't come out to it.