WAMP does not store

Asked

Viewed 191 times

2

Hello, there is no mistake, however 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");
?>

Grateful from now on.

  • Wamp is not the problem, Wamp means Windows, Apache, Mysql, Php. The problem was in using the mysqli API mixed with the mysql API. Wamp could not fail in this sense, since it is a set of software, which at most could fail is one of them separate :)

1 answer

3


Your connection is using functions of mysqli_*, and in your query you use mysql_*. The right thing to do is to adapt everything to Mysqli. But don’t think about any moment switch to Mysql! And a detail in that line:

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

You must rename $db for something that remembers connection, after all, $db does not store a database, but a Mysqli connection.

Rewriting your code, it’s like this:

Connection.php

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

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 lines I changed, renamed the variable in the connection.php and changed the method mysql_query for mysqli_query. Note that I also fixed an error in your SQL, you wrote value, the correct is VALUES.

For more information, read:

Browser other questions tagged

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