My form does not send to the bank

Asked

Viewed 70 times

0

I created a form to save data in the database Mysql, but it’s not working as expected.

I’m having trouble identifying the problem because no error appears, the page just a refresh.

Table in the Bank:

id_contato (int11 aI)
, nome_contato
, email_contato
, assunto_contato
, categoria_contato
, msg_contato

Form:

    include "seguranca.php";


    if(isset($_POST['submit']) )
    {
       $nome_contato=$_POST['nome_contato'];
       $email_contato=$_POST['email_contato'];
       $assunto_contato=$_POST['assunto_contato'];
       $categoria_contato=$_POST['categoria_contato'];
       $msg_contato=$_POST['msg_contato'];



       $msg_query = "INSERT INTO  contato (`nome_contato`, `email_contato`,`assunto_contato`, `categoria_contato`, `msg_contato`) VALUES ('$nome_contato', '$email_contato', '$assunto_contato','$categoria_contato', '$msg_contato')";
      try
      {
         $register_result = mysqli_query($conn, $msg_query);
         if($register_result)
         {
            if(mysqli_affected_rows($conn)>0)
            {
              echo("Mensagem enviada com sucesso!");
            }else{
               echo("Erro no envio da mensagem.");
            }
         }
      }
      catch(Exception $ex)
     {
        echo("error".$ex->getMessage());
     }
   }
?>
  <html>
  <body>
    <div class="col-md-3">
        <form method="POST" action="suporte.php" class="form-horizontal">
            <div class="form-group">
                <div class="col-sm-12">
                    <input type="text" class="form-control" id="Nome" 
         name="nome_contato" placeholder="Nome">
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-12">
                    <input type="email" class="form-control" id="Email" 
            name="email_contato" placeholder="Email">
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-12">
                    <input type="text" class="form-control" id="Assunto" 
              name="assunto_contato" placeholder="Assunto">
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-12">
                    <select class="form-control" name="categoria_contato" 
               id="Contato">
                        <option value="none" selected disabled>Selecione uma 
             opção de contato</option>
                        <option value="Suporte">Suporte</option>
                        <option value="Bug">Relatar um bug</option>
                        <option value="Sugestões">Sugestões</option>                            
                        <option value="Elogios">Elogios</option>
                        <option value="Reclamações">Reclamações</option>
                        <option value="Contato">Contato com a Cats2</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <div class="col-md-12">
                    <label id="Texto"> Mensagem: </label>
                    <textarea style="height: 134px; resize: none; width: 
                    330px;" class="form-control" rows="4" id="Texto" 
                   name="msg_contato">
                    </textarea>
                </div>
            </div>
            <div class="col-md-6"> 
                        <button class="btn-sm btn btn-default" type="submit" 
          name="submit" value="submit" > Enviar Mensagem</button>
            </div>
        </form>

    </div>
  </body>
  </html>

  • Presents some kind of error?

  • No guy, that’s why I can’t figure it out :(

  • You’re trying to use exceptions with Mysqli, but you set up Mysqli for this? Usually with Mysqli the error functions are used, which are much more practical and sensible than exceptions.

  • try usbistituri for single quotes

  • Do not have to put apostrophe in this part INSERT INTO contact (contact_name, email, & #Xa; contact, categorie_contact, msg_contact)

  • put in the form fields beyond the attribute name or id as well

  • remove the quote and put double quotes. Your Try/catch return treatment is also incorrect.

  • I put the Mysqli error functions, and added NULL to insert the ID in my msg_query. Now it’s working, thanks to all of you.

Show 3 more comments

1 answer

1

Why don’t you use the Pdo?

require_once('../conexao.php');

// Pegando os parametros
@$nome_contato = $_POST['nome_contato'];
@$email_contato = $_POST['email_contato'];

// @$nome_contato = ola;
// @$email_contato = "[email protected]";

$pdo = $dbconn->prepare("INSERT INTO contato (nome_contato, email_contato) VALUES (:nome_contato, :email_contato");
$pdo->bindParam(':nome', $nome);
$pdo->bindParam(':email_contato', $email_contato);
$pdo->execute();

Browser other questions tagged

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