problems when sending data to the database

Asked

Viewed 61 times

1

I’m now entering the programming part with mysql and php, and I’m doubtful, on the part of calling the database.vcs can help me out?

The codes I wrote:

<html>
<head>
<title> sistema de cadastro</title>
</head>

<body>
<form method="get="action="cadastrando.php">
nome: <input type="text" name="name"/> <b></b>
sobre nome: <input type="text" name="sobrenome"/><b> </b>
pais: <input type="text" name="pais"/> <b></b>
estado:<input type="text" name="estado"/> <b></b>
idade: <input type="text" name="cidade"/> <b></b>
e-mail: <input type="text" name="email"/> <b></b>
senha: <input type="password" name="senha"/> <b></b>
<input type="submit" value=""/>
</form>

</body>
</html>

///////////////////////////////////////////////////////////////////////////

<html>
<head>
<title> cadastramento</html>
</head>
<body>
<?php
$host ="localhost";
$user = "root";
$pass = "";
$banco= "cadastramento";
$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 usaname(NOME,SOBRENOME,PAIS,ESTADO,CIDADE,EMAIL,SENHA) values('$NOME','$SOBRENOME','$PAIS','$ESTADO','$CIDADE','$EMAIL','$SENHA')");
?>

</body>
</html>
  • Friend, your question is very vague and half meaningless. Post the codes you already have and try to explain better what you need.

  • 2

    I would recommend separating the view layer with the layer that connects to the database for better organization.

  • The best tip for a beginner me php, DO NOT use the mysql_* functions, prefer mysqli or Pdo.

1 answer

3

The problem is that the variables defined are in minuscules and the passings in the uppercase Insert, php is case sensitive for variables, so $nome is different from $NOME.

The name of the super global is $_POST uppercase.

The sending method is defined in the form

<form method="get="action="cadastrando.php">

Use $_GET to get and $_POST for post, I suggest you change the method for post.

<?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 usaname(NOME,SOBRENOME,PAIS,ESTADO,CIDADE,EMAIL,SENHA) values('$nome','$sobrenome','$pais','$estado','$cidade','$email','$senha')") or die(mysql_error());

Recommended reading:

Why should we not use mysql type functions_*?

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

Browser other questions tagged

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