Form does not pass variable - MYSQL to PHP

Asked

Viewed 264 times

0

I have a code called index.php, he must send the data to the post.php, to be stored within a database.

I’m doing it through form. When I store the form fields in the database it thinks I am sending the variable name, it follows the scripts and prints of the PHPMYADMIN.

Form index.php:

<html>
    <head>

        <meta charset="utf-8">
        <title>RH Question! </title>
    </head>
    <body><center>
            <form method="POST" action="post.php">
                <br>
                <br>
                <center><h1>HEADER BALA IMAGINARIO QUE VAI TER UM DIA AMEM DEUS</h1></center>

        <p>Digite o seu nome:</p> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  <input type="text" name="nome">
        <p>Digite o seu domínio:</p> &nbsp;&nbsp;   <input type="text" name="dominio">

        <input type="hidden" name="nome" value="<?php echo '$nome;' ?>">
        <input type="hidden" name="dominio" value="<?php echo '$dominio;' ?>">


            <input type="submit" value="Proximo" name="fim">
            </form></center>
    </body>
</html>

Filing cabinet post.php:

<html>
    <body>

<?php

// Inclui o arquivo que faz a conexão ao MySQL
include("conexao.php");

$nome = $_POST["nome"];
$dominio = $_POST["dominio"];

// Montamos a consulta SQL
$query = "INSERT INTO `registro` ( `nome`, `dominio`) VALUES ('".$nome."', '".$dominio."')";
// Executa a query
$inserir = mysql_query($query);
if ($inserir) {
echo "<center>Seu cadastro foi registrado, obrigado por entrar em contato!

<a href='selecao.html'>Clique aqui para continuar o seu filtro!</a></center>";
} else {
echo "Tente novamente!";
// Exibe dados sobre o erro:
echo "Dados sobre o erro:" . mysql_error();
}
?>
    </body>
</html>

How it’s being sent to the bank:

inserir a descrição da imagem aqui

  • 2

    No need to concatenate in your query see this way is more practical: $query = "INSERT INTO registro ( nome, dominio ) VALUES ('{$nome}', '{$dominio}')"; It is noticeable that it is sending the variable to the table its inputs hidden must be getting in the way. Since single quotation marks '' do not read variable try double quotation marks "" Here echo '$nome;'

  • I tried to make a change to the Insert you mentioned, but still it keeps picking the variable, in this case, its name and not the content, there is no error in my variable call? I removed the input="Hidden"

  • 1

    Raryson, with the call does not appear to have any errors, but as I told you, single quotes do not interpret php code, use double quotes, and input type hidden does not send information to the server, use readonly try to trade for <input readonly name="nome" value="<?php echo "$nome;" ?>">&#xA;<input readonly name="dominio" value="<?php echo "$dominio;" ?>">

1 answer

6


removes inputs[Hidden], they are overwriting the previous inputs[text]

<input type="hidden" name="nome" value="<?php echo '$nome;' ?>">

And put in their value(inputs[text]):

value="<?php echo $nome; ?>"

Browser other questions tagged

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