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> <input type="text" name="nome">
<p>Digite o seu domínio:</p> <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:
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 thetable
its inputshidden
must be getting in the way. Since single quotation marks '' do not read variable try double quotation marks "" Hereecho '$nome;'
– Guilherme SpinXO
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"
– Raryson Pereira Rost
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, usereadonly
try to trade for<input readonly name="nome" value="<?php echo "$nome;" ?>">
<input readonly name="dominio" value="<?php echo "$dominio;" ?>">
– Guilherme SpinXO