** il renvoie une erreurEn soumettant le formulaire, il renvoie une erreur
Indéfini offset: 0 dans C: \ xampp \ htdocs \ test_login \ add_data.php sur la ligne 10
ligne 10 a $ _SERVER [ "REQUEST_METHOD" == "POST"] **
<?php
require_once 'mysql_connect.php';
if ($_SERVER["REQUEST_METHOD" == "POST"]) {
if (empty($_POST['username'])) {
echo "Username required.";
}else{
$username = handle_data($_POST['username']);
}
if (empty($_POST['password'])) {
echo "Password required.";
}
else{
$password = handle_data($_POST['password']);
}
if ($_POST['cpassword'] != $_POST['password']) {
echo "Passwords donot match!";
}
if (!is_numeric($_POST['age'])) {
echo "Age must be a number.";
}
$query = "INSERT INTO students(username, password, age) VALUES(?, ?, ?)";
$stmt = mysql_stmt_prepare($conn, $query);
if ($stmt) {
mysqli_stmt_bind_param($stmt, 'ssi', $username, $password, $age);
mysqli_execute($stmt);
echo "Registration Made!";
mysqli_stmt_close($stmt);
mysqli_close($conn);
}
}
function handle_data($data){
$data = trim($data);
$data = stripcslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
Quelle est l'erreur réelle, il montre du doigt ??
Copie possible de [$ \ _ POST contre $ \ _ SERVER \ ['REQUEST \ _METHOD' \] == 'POST'] (https://stackoverflow.com/questions/409351/post-vs-serverrequest- method-post) – Jenish
Copie possible de [Référence - Que signifie cette erreur en PHP?] (https://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php) –
Il évalue '' "REQUEST_METHOD" == "POST" 'avec == signifiant comparer, donc cela retourne 0 car ils ne sont pas les mêmes et essayent donc de récupérer $ _SERVER [0]. –