Error In php variables

Asked

Viewed 28 times

0

I was trying to make the connection to the database, but the bank is only saving the ID user’s.

{$con = mysql_connect("localhost","root", "");

mysql_select_db("cadastro",$con);

$nome = $_POST['nome'];
$email = $_POST['email'];
$senha = $_POST['senha'];
$tdc = $_POST['tdc'];
$sql = mysql_query("INSERT INTO tb_usuarios(nome_usuario, email_usuario, senha_usuario, tdc_usuario) VALUES ('$nome', '$email', '$senha', '$tdc')");
?>}

After registration is giving these mistakes:

{Notice: Undefined index: nome in C:\xampp\htdocs\Controla\cadastrando.php on line 19

Notice: Undefined index: email in C:\xampp\htdocs\Controla\cadastrando.php on line 20

Notice: Undefined index: senha in C:\xampp\htdocs\Controla\cadastrando.php on line 21

Notice: Undefined index: tdc in C:\xampp\htdocs\Controla\cadastrando.php on line 22}

HTML:

<html>
<meta charset="utf-8">
<head>
    <title>Controla</title>
    <link rel="stylesheet" type="text/css" href="estilocadastro.css">
<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Fjalla+One" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Raleway" rel="stylesheet">
</head>
<body>
<div class="small"></div>

<div class="medium"></div>

<div class="large"></div>

<form name="sign" method="POST" action="cadastrando.php">

<header id="cabecalho">
<div class="interface">
<img id="Logo" src="imagens/controla.png" style="width:350px; height:355px; margin-left: 51%;">
</header>
<div class="menu">
    <ul>
        <li><a href="#">Página Inicial</a></li>
        <li><a href="login.php">Login</a></li>
        <li><a href="Cadastro.php">Cadastrar</a></li>
        <li><a href="#">Minha Conta</a></li>
    </ul>
</div>

<div class="central" style="z-index: 99999;top: 4em;"><br>
    <h1>CADASTRE - SE</h1>
</div>
<form action="cadastrando.php" method="POST">
<section>
<label style="font-family: 'Fjalla One'; color: #ffffff;">Nome Completo</label><br>
<input type="text" name="nome"><br>
<label style="font-family: 'Fjalla One'; color: #ffffff;">Email</label><br>
<input type="text" name="email"><br>
<label style="font-family: 'Fjalla One'; color: #ffffff;">Senha</label><br>
<input type="password" name="senha"><br>
<label style="font-family: 'Fjalla One'; color: #ffffff;">Tipo de comércio</label><br>
<input type="text" name="tdc"><br><br>
<a href="cadastrando.php"><img src="imagens/Botão.png" style="margin-left: -2px; margin-top: -1em; cursor: pointer;"></a>
</section>
</form>
<footer id="sobre">
<p> &copy; Controla Estoque 2018</p>

<h5 style="margin-left: -7.9em;position: relative;"> Um sistema de controle de estoque adequável para comercio de pequenas e microempresas, sendo padaria, pet shop, papelaria entre outros comércios existentes.</h5>

</footer>

</form>
</body>
</html>
  • If possible edit your question and post your HTML code.

  • the connection with the bank ta ok, but what is giving error is that it is not recognizing the variables, and I can not post the Tagas in html.

  • This function mysql* is obsolete, instead of using mysqli or PDO. https://imasters.com.br/banco-dados/mysql/mysql-obsoleto-utilize-funcoes-mysql_/? trace=1519021197&source=single

  • i am using php 5.6

  • php 5.6 has the mysqli, and PDO for Mysql as well. After all, 5.6 is one of the latest versions of PHP. Only recommendation, we are not forcing you, but should not use obsolete and deprecated functions.

  • to making tcc project brother, I’m using php 5.6 thanks for the teachers.

Show 1 more comment

1 answer

0


The error is because you are redirecting the user (through the tag <a>, instead of sending the form data.

There are 3 ways to send form data:

  • Knob

    <button type="submit">Cadastrar</button>

  • Input Submit

    <input type="submit" value="Cadastrar" />

  • Ajax

    /a/279001/99718


To fix just replace:

<a href="cadastrando.php"><img src="imagens/Botão.png" style="margin-left: -2px; margin-top: -1em; cursor: pointer;"></a>

For:

<button type="submit">Cadastrar</button>

Or else:

<button type="submit" style="background:url('imagem.png');height:75px;width:75px"></button>

Browser other questions tagged

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