Save Mysql php data to a single table

0

I'm having a small question on how to save a form in mysql that is. I have a form that is divided into 2 and I want it to be saved in the same table.

When I save I only save the second part of mysql it deletes the first one to me.

Example Form1: Name, function Insert in DB:

$sqlinsert = "Insert into tb_trabalhador (Nome, funcao) Values ('".$Nome."','".$Funcao."')";

mysql_query($sqlinsert) or die(mysql_error());
if ($sqlinsert)

Form 2: Birthdate, date of birth Insert in DB:

$sqlinsert = "Insert into tb_trabalhador (Cartao, Data) Values ('".$Cartao."','".$Data."')";

 mysql_query($sqlinsert) or die(mysql_error());
 if ($sqlinsert)
    
asked by anonymous 12.06.2014 / 17:43

1 answer

4

The problem is that it seems to me that you want to merge the data into one record, but you are creating two.

After using each of your codes, you will get a table like this:

Cartao | Data       | Nome   | Funçao
-------+------------+--------+--------
2136   | 31/05/2014 |        |
-------+------------+--------+--------
       |            | Holmer | Estivador

If you want to add data to a table, you'll need something like this:

$cartao = "2136" // esse é só um exemplo, pode ser ID, aí vai depender do seu caso.
$sqlupdate = "UPDATE tb_trabalhador". // ATUALIZE tb_trabalhador
    "SET Nome=$nome, Funcao=$Funcao". // mudando o nome pra $Nome e função pra $Funcao
    "WHERE Cartao=$Cartao";           // na linha em que o cartão for $Cartao

Note: This is just an example. As you may have already been warned in some of your previous questions, you should be using mysqli_ functions to use bindParameter , instead of creating the parameter string, but this is another problem.

    
12.06.2014 / 19:14