1
Guys, I imagine this doubt is recurring. I even looked for some alternatives but did not work.
I have a Screen where I record Service Orders with Client and PC data from it. It turns out that. I am filling 2 Tables simultaneously.
On the table tb_os
i record The Service Orders themselves(complete). And in the table clientes
i only record customer information in case I want to make only my customer list(which I can use elsewhere in my sisteminha).
But as my client table is already getting a little big, I didn’t want to spend all the time at risk of registering the same customer, with the same name, address etc.
My functional code is this:
$sql = " insert into tb_os (os_status, cliente, telefone, celular, email, endereco, endereco_num, complemento, bairro, cep, tipo, marca, modelo, processador, memoria, hd, acompanha, ordem_servico )";
$sql.= " values ( '$os_status', '$cliente', '$telefone', '$celular', '$email', '$endereco', '$numero', '$complemento', '$bairro', '$cep', '$tipo', '$marca', '$modelo', '$processador', '$memoria', '$hd', '$acompanha', '$texto_os' ) ";
sql2 = " INSERT INTO clientes (cliente, email) VALUES ('$cliente', '$email') ";
if (mysqli_query($link, $sql) AND mysqli_query($link, $sql2)){
$mail = $email;
$to = $email;
Where I conclude with an email sent to the client. Until then I complete the 2 tables.
Then I tried it to prevent it from populating with repeated information:
if(mysqli_query($link, "SELECT * FROM clientes WHERE cliente = '".$cliente."'")) {
$sql2 = "UPDATE clientes Set cliente = '".$cliente."', telefone = '".$telefone."' WHERE cliente = '".$cliente."' ";
} else {
$sql2 = "INSERT INTO clientes (cliente, telefone) VALUES ('".$cliente."', '".$telefone."')";
}
But in doing so, he simply ignores my request to update
in clientes
and register the tables tb_os
normally.
In these tables as primary keys I have id_os
in tb_os
and id_cliente
in clientes
. But I don’t know if it helps at all.
Can anyone give me a light? Any way to check if the registration with name Client already exists, if there is only update?
Hug guys and good Sunday leftover if there’s someone walking around here today kkkk.
Programmer really has a differentiated watch kkkkkkkkkk I ended up using the tip of Leo, as I do not yet know of database functions. But I already got the link here to study, because the idea is very good (And practice too, even for a more complete code). Thanks for the help Renan. Have a great week!
– Rafael