Error In variables in php

0

I tried to connect to the database, but the database is only saving the ID of the user.

{$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 you are giving these errors:

{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>
    
asked by anonymous 01.03.2018 / 06:35

1 answer

0

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

There are 3 ways to submit form data:

  • Button

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

  • Input Submit

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

  • Ajax

    link

To fix just replace:

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

By:

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

Or:

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