Hello !
When i submit my form the code did not perform the “if”, it take the “else”.
Why ?
The code:
<?php
// Date MySQL;
$username = "encodare";
$password = "***";
$host = "***";
$db = "encodare_troll_mc";
// Conectare MySQL;
$connect = new mysqli($host, $username, $password, $db);
// Verific conexiunea;
if ($connect->connect_error)
die("Conexiunea cu baza de date a esuat: ".$connnect->connect_error);
// Daca se conecteaza, executa:
session_start();
// Register (register.php)
if (isset($_POST['Register']))
{
if (!($connect->query("SELECT IP FROM Users WHERE IP = '{$_SERVER["REMOTE_ADDR"]}'")))
{
$insert = $connect->prepare("INSERT INTO Users (IP, Username, Age, Email, Password) VALUES (?, ?, ?, ?, ?)");
$insert->bind_param("sssss", $IP, $Username, $Age, $Email, $Password);
$IP = $_SERVER['REMOTE_ADDR'];
$Username = $_POST['Username'];
$Age = $_POST['Age'];
$Email = $_POST['Email'];
$Password = $_POST['Password'];
if(!$insert->execute())
mysqli_error($connect);
$_SESSION['succes'] = "Te-ai înregistrat cu succes !\n";
$_SESSION['succes'] .= "Ai primit un email cu numele de utilizator si parola.";
header('Location: index.php');
}
else
{
$_SESSION['error'] = "Esti deja înregistrat.";
header('Location: index.php');
}
}
?>
<form name="RegisterForm" method="post" style="width: 50%; margin: auto;">
<input type="hidden" name="Register" value="Register"/>
<h1 class="frh1">Inregistrare</h1>
<div class="box">
<span class="fa fa-user icon"></span>
<input class="field" type="text" name="Username" placeholder="Ce nume de utilizator doreşti ?" required/>
</div>
<div class="box">
<span class="fa fa-question icon"></span>
<input class="field" type="text" name="Age" placeholder="Câţi ani ai ?" required/>
</div>
<div class="box">
<span class="fa fa-envelope icon"></span>
<input class="field" type="text" name="Email" placeholder="Scrie-ne email-ul tău, te rog." required/>
</div>
<div class="box">
<span class="fa fa-lock icon"></span>
<input class="field" type="password" name="Password" placeholder="Ce parola doreşti ?" required/>
</div>
<button class="submit" name="submit">Inregistreaza-ma</button>
</form>