Well, I suppose this question is recurrent. I even tried some alternatives but they did not work.
I have a Screen where I record Service Orders with the Client and PC data. It turns out that. I am filling 2 Tables simultaneously.
In the tb_os
table I record the Service Orders itself (complete). And in the clientes
table I only record client information if I just want to make my client list (which I can use elsewhere in my system).
But since my client table is already getting a little big, I did not want to spend all the time running the risk of registering the same client, 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 to the customer. So far right filling out the 2 tables.
I tried this to prevent it from popping up 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 by doing this, it simply ignores my request for update
in clientes
and registers the tb_os
tables in a normal way.
In these tables as primary keys I have id_os
in tb_os
and id_cliente
in clientes
. But I do not know if this helps in any way.
Can anyone give me a light? Is there a way to check if the registry with the Client name already exists, if there is only an update?
I do not know what to do.