My database is changing the last name by the registered name and no email appears

Asked

Viewed 91 times

3

File that records:

<html>
<head>
<meta charset="utf-8">
<title>cadastrando...</title>
</head>
<body>
<?php
$host = "localhost";
$user = "root";
$pass = "";
$banco = "cadastro";
$conexao=@mysql_connect($host,$user, $pass) or die(mysql_error());
mysql_select_db($banco) or die(mysql_error());
?>
<?php
$nome=$_POST['Nome'];
$sobrenome=$_POST ['Sobrenome'];
$pais=$_POST['pais'];
$estado=$_POST['estado'];
$cidade=$_POST['cidade'];
$email=$_POST['Email'];
$senha=$_POST['senha'];
$sql = mysql_query("INSERT INTO usuarios(nome, sobrenome, pais, estado, cidade, email, senha)
VALUES('$nome', '$Sobrenome', '$pais', '$estado', '$cidade', '$Email', '$senha')");
echo "Cadastro efetuado com sucesso!!!"
?>
</body>
</html>

Form

<html>
<head>
<meta charset="utf-8">
<title>Sistema de Cadastro</title>
</head>
<body>
<form name="signup" method="post" action="cadastrando.php">
nome: <input type="text" name="nome" /> </br></br>
sobrenome: <input type="text" name="Sobrenome" /> </br></br>
Pais: <input type="text" name="pais" /> </br></br>
Estado: <input type="text" name="estado" /> </br></br>
Cidade: <input type="text" name="cidade" /> </br></br>
E-mail: <input type="text" name="Email" /> </br></br>
Senha: <input type="password" name="senha" /> </br></br>
<input type="submit" value="Cadastrar" />
</body>
</html>
  • First adjust the names of variables in the Index: ('$name', '$surname', '$parents', '$state', '$city', '$email', '$password')

  • Tip: If you are populating all fields in the table with the information, you can exchange insert into usuarios(nome, sobrenome, pais, estado...) values(...) by just INSERT INTO USUARIOS VALUES(....). So your query gets more simplified, since you don’t need to specify the fields, since you will insert data in all of them.

1 answer

3

Variables in php are case sensitive, upper case are different minuscules, so: $nome is different from $Nome. The values sent by the form must be the same recovered by $_POST, <input type="text" name="nome" /> is different from $_POST['Nome'];

If starting already started badly, the mysql_* functions have already been discontinued and will soon be removed, use a modern API for connection like database like Mysqli or PDO.

I suggest you box all the names,

form

nome: <input type="text" name="nome" /> </br></br>
sobrenome: <input type="text" name="sobrenome" /> </br></br>
Pais: <input type="text" name="pais" /> </br></br>
Estado: <input type="text" name="estado" /> </br></br>
Cidade: <input type="text" name="cidade" /> </br></br>
E-mail: <input type="text" name="email" /> </br></br>
Senha: <input type="password" name="senha" /> </br></br>        

cadastra.php

//código omitido
$nome = mysql_real_escape_string($_POST['nome']);
$sobrenome = mysql_real_escape_string($_POST ['sobrenome']);
$pais = mysql_real_escape_string($_POST['pais']);
$estado = mysql_real_escape_string($_POST['estado']);
$cidade = mysql_real_escape_string($_POST['cidade']);
$email = mysql_real_escape_string($_POST['email']);
$senha = mysql_real_escape_string($_POST['senha']);

$query = "INSERT INTO usuarios(nome, sobrenome, pais, estado, cidade, email, senha)
          VALUES('$nome', '$Sobrenome', '$pais', '$estado', '$cidade', '$email', '$senha')";

$sql = mysql_query($query) or die(mysql_error())

Recommended reading:

Mysqli vs PDO - which is the most recommended to use?

Why should we not use mysql type functions_*?

How to convert a MYSQL connection to MYSQLI?

Using PDO is the safest way to connect to a PHP BD?

  • It may not even be his fault, nowadays it is still more likely to find a tutorial explaining how to connect using the mysql instead of the mysqli, another recommendation is to put in your answer, so that it removes the space in $_POST * ["sobrenome"].

  • Looking at the date of the tutorial is very important.

  • 1

    +1, for example, and recommendations -.

Browser other questions tagged

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