3
I have a page with a field for entries that are recorded in the database and when recording I assign a user ID randomly in this register.
Thus:
$name = $_POST['name'];
$phone1 = $_POST['phone1'];
$time = $_POST['time'];
$client = $_POST['client'];
$sql = "SELECT * FROM `tblUsers` where grupo = 'contato' and ativo = 1 and periodo = 'manha' ORDER BY RAND() LIMIT 1";
$resultado = $pdo ->query($sql);
if($resultado !== false)
{
foreach($resultado as $row)
{
$randomicId = $row['idVendedor'];
}
}
In the above SQL I take a random ID of my users and assign the $randomicId variable.
At the time of inserting in the bank:
$stmt = $pdo->prepare('INSERT INTO tblContacts(name,phone1,time,client,date,hourSend,qtd,origem,idUsuario)VALUES(:name,:phone1,:time,:client,:date,:hourSend,:qtd,:origem,:idUsuario)');
$stmt->execute(array(':name' => $name,':phone1' => $phone1,':time' => $time, ':client' => $client, ':date' =>$date, ':hourSend' => $hour , ':qtd' => $qtd, ':origem'=> $origem,':idUsuario'=>$randomicId));
So far everything happens normal, after saving I select and display this data to the logged users according to their ID.
My problem is the repeated registrations, because I wanted to record even if they were repeated.
For example:
- no day 1 so-and-so made a registration and recorded in the bank for ID user 32.
- no day 3 so did another registration, but this time recorded in the bank ID user 20.
Thus, I would be sending 2 entries to the same user.
How to verify if the registration already exists and if it already exists save the same user ID in the bank ?
ps.: The 'phone1' field will hardly be equal as there are no 2 equal phones. It could be used to make the comparison.
If a person fills in the wrong phone, will redo the form with the right phone... this would already break the check by phone. Same with the name...
– NovoK
So , but how could I check ? Ps.: In the phone field , I already do the treatment not to come with missing number, letter, etc. the problem would be same as Cvoce said , if the person type wrong . But , still ,it is difficult to occur .
– Henrique Felix
Before generating random ID you cannot give a
SELECT
intblContacts
searching for the client and returning theidUsuario
? If find, use it, otherwise you generate the random.– Maicon Carraro
I tried to do so , but is not saving any ID now : $sql = "SELECT * FROM
tblContacts
Where phone1 = '$phone1' "; $result = $Pdo ->query($sql); if($result !== false) { foreach($result as $Row) { $randomicId = $Row['idVendedor']; } } Else Sql that will generate the random ID }– Henrique Felix
boy, tips that work me, I like to make this type of registration, of very elaborate, today I have the perfect function, since you have Name, Phone, Time and Client, in case, I do not know exactly how you use this Time, but, the name, I believe that there is only one person with a name and surname in your system that belongs to the team such and has the phone such, the site you can do to compare all of them, ie when you type the name and surname, go in the database and search, when it finds, it shows a green message for the user to know that it is correct because it has already done so, so the
– flourigh
Did any of the answers help?
– Vinícius Lima