vendredi 5 mars 2021

Is there a way to add priority to a php echo message?

I have

if (stripos($username, '')) {
echo 'You need to have a username';
}else{
if (stripos($password, '')) {
echo 'You need to have a password';
}else{
if (stripos($email, '')) {
echo 'You need to have a email';
}else{
if (!stripos($email, '@')) {
echo 'You need to have a valid email';

everytime i put in my email but not my username and password it says i need to put a valid email. why is this happening and how do I fix it? I thought about priorities but I don't know how or what to do that...

the rest of the code on the page is as follows

<?php
error_reporting(0);
session_start();
require_once('config.php');


$username = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];
$valid = "You need to have a valid Email Address";

$sql = "SELECT * FROM accounts WHERE username=? and password=? and email=? LIMIT 1";
$stmtselect  = $db->prepare($sql);
$result = $stmtselect->execute([$username, $password, $email]);

if (stripos($password, '')) {
echo 'You need to enter a Password';
}else{
if (stripos($username, '')) {
echo 'You need to enter a Username';
}else{
if (stripos($email, '')){
echo 'You need to enter a Email Address';
}else{
if (!stripos($email, '@')) {
echo $valid;
}else{
if (!stripos($email, '.')) {
echo $valid;
}else{
if (!stripos($email, 'com')){
echo $valid;
}else{
if($result){
    $user = $stmtselect->fetch(PDO::FETCH_ASSOC);
    if($stmtselect->rowCount() > 0){
    $_SESSION['accounts'] = $user;
    echo 'You have signed in successfully!';
}else{
    echo 'Incorrect Username or Password or Email';     
}
}else{
echo 'There were errors while connecting to database.';
}
}
}
}
}
}
}

Please don't say anything about having the password as plain text.

Aucun commentaire:

Enregistrer un commentaire