2
In my database I have a table called
register
- id_cadastro
- name_user
- email_user
- idade_user
- overuser
- fb_user
- tt_user
- in_user
- avatar_user
This is the information I use for logging in. However, after registering in this table the user is redirected to a page where he selects whether he is a physical or legal person, containing other information
personal
- id_fisica
- id_user
- cpf_user
- rg_user
- phone_user
- cellular_user
- cep_user
- city_user
- state_user
- address_user
- numero_user
- bairro_user
The personal table changes only the field for cnpj, state and municipal registration, besides is equal. But when the user will update the information he needs to update these two tables and I do not know how to do two UPDATES in a php file. 'Cause I’m just using a form
form
<form method="post" action="php/atualizarFisica.php" enctype="multipart/form-data">
<div class="col-md-4 col-sm-12">
<div class="form-group">
<label>Nome Completo <span class="required">*</span></label>
<input placeholder="" name="nome" class="form-control" type="text" value="<?php echo $_SESSION['nome_user']; ?>" required>
</div>
</div>
<div class="col-md-4 col-sm-12">
<div class="form-group">
<label>E-mail <span class="required">*</span></label>
<input placeholder="" name="email" class="form-control" type="email" value="<?php echo $_SESSION['email_user']; ?>" required>
</div>
</div>
<div class="col-md-4 col-sm-12">
<div class="form-group">
<label>Data Nascimento <span class="required">*</span></label>
<input placeholder="" name="idade" class="form-control" type="text" value="<?php echo $_SESSION['idade_user']; ?>">
</div>
</div>
<div class="col-md-6 col-sm-12">
<div class="form-group">
<label>Telefone <span class="required">*</span></label>
<input placeholder="" name="telefone" class="form-control" type="text" value="<?php echo $row_fisica['telefone_user']; ?>">
</div>
</div>
<div class="col-md-6 col-sm-12">
<div class="form-group">
<label>Celular <span class="required">*</span></label>
<input placeholder="" name="cel" class="form-control" type="text" value="<?php echo $row_fisica['cel_user']; ?>">
</div>
</div>
<div class="col-md-12 col-sm-12 mg-t">
<div class="form-group">
<label>Sobre você: </label>
<textarea cols="6" name="sobre" rows="8" placeholder="" class="form-control"><?php echo $_SESSION['sobre_user']; ?></textarea>
</div>
</div>
<div class="col-md-12 col-sm-12">
<div class="heading-inner">
<p class="title">Informações Pessoais</p>
</div>
</div>
<div class="col-md-6 col-sm-12">
<div class="form-group">
<label>CPF <span class="required">*</span></label>
<input placeholder="" name="cpf" class="form-control" type="text" value="<?php echo $row_fisica['cpf_user']; ?>">
</div>
</div>
<div class="col-md-6 col-sm-12">
<div class="form-group">
<label>RG <span class="required">*</span></label>
<input placeholder="" name="rg" class="form-control" type="text" value="<?php echo $row_fisica['rg_user']; ?>">
</div>
</div>
<div class="col-md-6 col-sm-12">
<div class="form-group">
<label>Estado <span class="required">*</span></label>
<input placeholder="" name="estado" class="form-control" type="text" value="<?php echo $row_fisica['estado_user']; ?>">
</div>
</div>
<div class="col-md-6 col-sm-12">
<div class="form-group">
<label>Cidade <span class="required">*</span></label>
<input placeholder="" name="cidade" class="form-control" type="text" value="<?php echo $row_fisica['cidade_user']; ?>">
</div>
</div>
<div class="col-md-6 col-sm-12">
<div class="form-group">
<label>CEP <span class="required">*</span></label>
<input placeholder="" name="cep" class="form-control" type="text" value="<?php echo $row_fisica['cep_user']; ?>">
</div>
</div>
<div class="col-md-6 col-sm-12">
<div class="form-group">
<label>Endereco <span class="required">*</span></label>
<input placeholder="" name="endereco" class="form-control" type="text" value="<?php echo $row_fisica['endereco_user']; ?>">
</div>
</div>
<div class="col-md-6 col-sm-12">
<div class="form-group">
<label>Numero <span class="required">*</span></label>
<input placeholder="" name="numero" class="form-control" type="text" value="<?php echo $row_fisica['numero_user']; ?>">
</div>
</div>
<div class="col-md-6 col-sm-12">
<div class="form-group">
<label>Bairro <span class="required">*</span></label>
<input placeholder="" name="bairro" class="form-control" type="text" value="<?php echo $row_fisica['bairro_user']; ?>">
</div>
</div>
<div class="col-md-12 col-sm-12">
<div class="heading-inner">
<p class="title">Senha</p>
</div>
</div>
<div class="col-md-6 col-sm-12">
<div class="form-group">
<label>Nova Senha </label>
<input placeholder="" name="senha" class="form-control" type="password">
</div>
</div>
<div class="col-md-6 col-sm-12">
<div class="form-group">
<label>Confirma Nova Senha </label>
<input placeholder="" name="senha" class="form-control" type="password">
</div>
</div>
<div class="col-md-12 col-sm-12">
<div class="heading-inner">
<p class="title">Mídias Sociais</p>
</div>
</div>
<div class="col-md-4 col-sm-4 col-xs-12">
<div class="input-group">
<span class="input-group-addon" id="basic-addon1"><i class="fa fa-facebook" aria-hidden="true"></i></span>
<input type="text" class="form-control" name="fb" placeholder="Facebook" aria-describedby="basic-addon1" value="<?php echo $_SESSION['fb_user']; ?>">
</div>
</div>
<div class="col-md-4 col-sm-4 col-xs-12">
<div class="input-group">
<span class="input-group-addon" id="basic-addon1"><i class="fa fa-twitter" aria-hidden="true"></i></span>
<input type="text" class="form-control border-field" name="tt" placeholder="Twitter" aria-describedby="basic-addon1" value="<?php echo $_SESSION['tt_user']; ?>">
</div>
</div>
<div class="col-md-4 col-sm-4 col-xs-12">
<div class="input-group">
<span class="input-group-addon" id="basic-addon1"><i class="fa fa-instagram" aria-hidden="true"></i></span>
<input type="text" value="<?php echo $_SESSION['in_user']; ?>" class="form-control border-field" name="in" placeholder="Instagram" aria-describedby="basic-addon1">
</div>
</div>
<div class="col-md-2 col-sm-2 mg-t">
<img src="images/users/<?php echo $_SESSION['avatar_user']; ?>" alt="" class="profile-img img-responsive" />
</div>
<div class="col-md-10 col-sm-10 mg-t">
<div class="form-group">
<label for="exampleInputFile">Imagem Perfil</label>
<input type="file" class="form-control-file" name="avatar[]" id="exampleInputFile" aria-describedby="fileHelp">
<small id="fileHelp" class="form-text text-muted">Caso queira alterar sua imagem de perfil basta clicar no botão acima.</small>
</div>
</div>
<div class="col-md-12 col-sm-12">
<button name="submit" class="btn btn-default pull-right"><i class="fa fa-save"></i> Salvar </button>
</div>
</form>
php update.
<?php
session_start();
require_once('conexao/conexao.php');
$id_user = $_SESSION['id_cadastro'];
if(!empty($_POST['nome'])
&& !empty($_POST['email'])
&& !empty($_POST['telefone'])
&& !empty($_POST['cpf'])
&& !empty($_POST['rg'])){
$nome = $_POST['nome'];
$email = $_POST['email'];
$idade = implode("-",array_reverse(explode("/",$_POST['idade'])));
$telefone = $_POST['telefone'];
$cel = $_POST['cel'];
$sobre = $_POST['sobre'];
$cpf = $_POST['cpf'];
$rg = $_POST['rg'];
$estado = $_POST['estado'];
$cidade = $_POST['cidade'];
$cep = $_POST['cep'];
$endereco = $_POST['endereco'];
$numero = $_POST['numero'];
$bairro = $_POST['bairro'];
$senha = ($_POST['senha'])?md5($_POST['senha']):false;
$fb = $_POST['fb'];
$tt = $_POST['tt'];
$in = $_POST['in'];
$avatar = $_FILES['avatar'];
/* Descobrir se o email já existe */
$iguais = "SELECT * FROM cadastro
WHERE email_user LIKE '%{$email}%'
AND id_user != {$id_user}";
$iguais_query = mysql_query($iguais, $con);
$row_iguais = mysql_fetch_assoc($iguais_query);
if (mysql_num_rows($iguais_query) > 0) {
$_SESSION['aviso'] = "O Email $email ja esta sendo usado";
header('location: ../user-edit-profile.php');
exit;
} else{
$update = "UPDATE cadastro
SET
A.nome_user = '{$nome}',
A.email_user = '{$email}',
A.idade_user = '{$idade}',
A.sobre_user = '{$sobre}',";
if($senha){
$update .= "A.senha_user = '{$senha}',";
}
$update .= "A.fb_user = '{$fb}',
A.tt_user = '{$tt}',
A.in_user = '{$in}',
B.cpf_user = '{$cpf}',
B.rg_user = '{$rg}',
B.estado_user = '{$estado}',
B.cidade_user = '{$cidade}',
B.cep_user = '{$cep}',
B.endereco_user = '{$endereco}',
B.numero_user = '{$numero}',
B.bairro_user = '{$bairro}',
B.telefone_user = '{$telefone}',
B.celular_user = '{$cel}'
FROM cadastro A
INNER JOIN pessoa_fisica B ON B.id_user = A.id_cadastro
WHERE A.id_cadastro = '{$id_user}'";
$executaUp = mysql_query($update, $con);
if(mysql_affected_rows($con) > 0){
$_SESSION['certo'] = "Atualizado com sucesso";
header('location: ../user-dashboard.php');
exit;
} else{
echo "Ocorreu um erro na atualização das informações";
print_r($update);
}
} //ELSE UPDATE SEM AVATAR
} else{
$_SESSION['aviso'] = "Preencha os campos necessários.";
header('location: ../user-edit-profile.php');
exit;
}
?>
Here is only doing the UPDATE in the table register, I want to know how to do the UPDATE in the table personal if the user changes any field related to that table.
Related https://answall.com/questions/176946/update-em-v%C3%A1rias-tables-with-the-same-column? Rq=1
– user60252