WAMP does not store

2

Hello, you are not giving any errors, but WAMP does not save the information.

Code of cadastro_db.php :

<?
include("conection.php");

$nome = $_POST['nome'];
$email = $_POST['email'];
$idade = $_POST['idade'];
$cidade = $_POST['cidade'];
$login = $_POST['login'];
$senha = $_POST['senha'];

$sql = mysql_query("INSERT INTO usuarios(nome, email, idade, cidade, login, senha, foto) value('$nome',                     '$email', '$idade', '$cidade', '$login', '$senha', '$foto')");
header("Location: index.php");  

?>

Code of conection.php :

<?
$db = mysqli_connect("localhost", "root", "");
mysqli_select_db($db, "login_senha");
?>

Thank you in advance.

    
asked by anonymous 25.04.2015 / 02:51

1 answer

3

Your connection is using mysqli_* functions, and in your query you use mysql_* . The correct thing is you adapt everything to MySQLi. But do not think at all switch to MySQL ! And one detail, in this line:

$db = mysqli_connect("localhost", "root", "");

You should rename $db to something that reminds connection, after all, $db does not save a database, but a MySQLi connection.

Rewriting your code, it looks like this:

connection.php

<?php
  $con = mysqli_connect("localhost", "root", "");
  mysqli_select_db($con, "login_senha");
?>

cadastro_db.php

<?php
  include("conection.php");

  $nome = $_POST['nome'];
  $email = $_POST['email'];
  $idade = $_POST['idade'];
  $cidade = $_POST['cidade'];
  $login = $_POST['login'];
  $senha = $_POST['senha'];

  $sql = mysqli_query($con, "INSERT INTO usuarios(nome, email, idade, cidade, login, senha, foto) VALUES ('$nome', '$email', '$idade', '$cidade', '$login', '$senha', '$foto')");
  mysqli_close($con); // Fecha a conexão antes de redirecionar
  header("Location: index.php");
?>

Pay attention to the rows I've changed, renamed the variable in connection.php , and changed method mysql_query to mysqli_query . Note that I also fixed an error in your SQL, you typed value , correct VALUES .

For more information, read:

25.04.2015 / 03:04