fail, log data into Database

Asked

Viewed 56 times

0

Hello, I’m having some problems trying to register the form data in the bd,

Form code:

<form class="form-horizontal" method="post" action="processa/proc_cad_star.php">
<div class="form-group">
    <label for="inputEmail3" class="col-sm-2 control-label">Nome</label>
        <div class="col-sm-10">
            <input type="texto" class="form-control" name="nome" placeholder="Nome Popular">
        </div>
</div>

<div class="form-group">
    <label for="inputEmail3" class="col-sm-2 control-label">Sexo</label>
        <div class="col-sm-10">
            <label class="radio-inline">
                <input type="radio" name="sexo" value="F">F
            </label>
            <label class="radio-inline">
                <input type="radio" name="sexo" value="M">M
            </label>
        </div>
</div>

<div class="form-group">
    <label for="inputEmail3" class="col-sm-2 control-label">País</label>
        <div class="col-sm-10">
            <input type="texto" class="form-control" name="pais" placeholder="País Atual">
        </div>
</div>


<div class="form-group">
    <label for="inputEmail3" class="col-sm-2 control-label">Cidade Natal</label>
        <div class="col-sm-10">
            <input type="texto" class="form-control" name="cidade" placeholder="Onde Nasceu">
        </div>
</div>


<div class="form-group">
    <label for="inputEmail3" class="col-sm-2 control-label">Tattoo</label>
        <div class="col-sm-10">
            <label class="radio-inline">
                <input type="radio" name="tattoo" value="Yes">Yes
            </label>
            <label class="radio-inline">
                <input type="radio" name="tattoo" value="None">None
            </label>
        </div>
</div>




<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
  <button type="submit" class="btn btn-success">Cadastrar</button>
</div>
</div></form>`

proc_cad_star.php page:

<?php   session_start();
include_once("../seguranca.php");

include_once("../conexao.php");

$nome = $_POST["nome"];
$sexo = $_POST["sexo"];
$pais = $_POST["pais"];
$cidade = $_POST["cidade"];
$tattoo = $_POST["tattoo"];
//Apenas para simplificar o post aqui no site
//Primeira tentativa
$result = $mysqli->query("SELECT COUNT(*) FROM usuario WHERE nome = '$nome' ");
$row = $result->fetch_row();
   if ($row[0] > 0) {
        $alerta =("seu (".$nome.") já existente.");
    } else {
        $alerta =("Cadastro realizado com sucesso");
        $mysqli->query("INSERT INTRO usuario (nome, sexo, pais, cidade, tattoo, created) VALUES ('".$nome."','".$sexo."','".$pais."','".$cidade."', '".$tattoo."', NOW())");
    }    

 //Segunda tentativa        
$query = mysqli_query("INSERT INTRO usuario (nome, sexo, pais, cidade, tattoo, created) VALUES ('".$nome."','".$sexo."','".$pais."','".$cidade."', '".$tattoo."', NOW())");
if (mysqli_affected_rows() != 0){
header("location: ../listar_star.php");
}
?>

The first attempt does not present any error, but does not record.

The second attempt presents the following errors:

Warning: mysqli_query() expects at least 2 Parameters, 1 Given in

Warning: mysqli_affected_rows() expects Exactly 1 Parameter, 0 Given in

Does anyone know how to correct? I can’t find the error. Thank you

  • 1

    In procedural form, you need to pass the link (the variable containing the connection) as a parameter for both the query and affected_rows. Try and see if it works properly.

  • Passed! but did not record the data. Any suggestions?

  • 1

    Try removing R from INTRO to INSERT INTO and see if it works.

  • Thank you very much man !! Solved... now ta spinning fine.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.