How do you have PHP code on standby (idle)? [closed]

33
September 14, 2021, at 8:30 PM
Closed. This question needs details or clarity. It is not currently accepting answers.

Want to improve this question? Add details and clarify the problem by editing this post.

Closed 10 hours ago.

Improve this question

I have been trying to build a log-in system with SQL and Ajax and a problem that I am facing is communicating with the PHP because I can not continuously run the code. I tried using while and running the AJAX but that does not work either, it only infinitely returns errors about how ho_id and so on are undefined.

My AJAX:

var fname = $("fname").val();
var lname = $("lname").val();
var email = $("email").val();
var pass = $("pass").val();
$.post("data.php", "ho_id="+ho_id+"fname="+fname+"lname="+lname+"email="+email+"pass="+pass);
const xmlhttp = new XMLHttpRequest();
xmlhttp.onload = function(){alert(xmlhttp.responseText)}
xmlhttp.open("GET", "data.php?q=status");
xmlhttp.send();

My PHP:

   
<?php
    $ho_id = $_POST['ho_id'];
    $email = $_POST['e-mail'];
    $pass = $_POST['pass'];
    $gend = $_POST['genders'];
    $fname = $_POST['fname'];
    $lname = $_POST['lname'];
    
    $conn = new mysqli('localhost','root','','log-in-details');
    if($conn->connect_error){
        die("Connection Failed: " .$conn->connect_error);
    }else{
        $sql = "SELECT ho_id, email, pass, gend FROM userinfo WHERE ho_id = $ho_id";
        $result = $conn->query($sql);
        $sql1 = "SELECT ho_id, email, pass, gend FROM userinfo WHERE email = '$email'";
        $result1 = $conn->query($sql1);
        if ($result or $result1) {
            if ($result->num_rows >= 1 or $result1->num_rows >= 1) {
                sleep(1);
                $status = $_REQUEST["status"];
                echo "Failed";
                
                die();
                exit();
            }
        }
        else if ($result1){
            if ($result1->num_rows >= 1) {
                
                $status = $_REQUEST["status"];
                echo "Failed";
                die();
                exit();
            }
        }
        else{
            $status = $_REQUEST["status"];
               echo "Success";
            }   
        $stmt = $conn->prepare("INSERT INTO userinfo(fname, lname, email, pass, gend, ho_id)
        values(?, ?, ?, ?, ?, ?)");
        $stmt->bind_param("sssssi",$fname, $lname, $email, $pass, $gend, $ho_id);
        $stmt->execute();
        $stmt->close();
        $conn->close();          
    }
?>

I have tried running them both on the same file, but the errors from the PHP spill onto the webpage.

I use Chrome and XAMPP to run my PHP by the way.

READ ALSO
React changing state of specific element on button click

React changing state of specific element on button click

I'm building a React component thats basically a dropdown of sorting optionsWhen a user clicks on a sort selection, the UI will update in accordance to the user's selection

15
How to add a folder to gallery in React Native

How to add a folder to gallery in React Native

I'd like to add a folder to the gallery in React Native, like Instagram or WhatsApp have oneCould you tell me how to do that in React Native for Android and iOS ?

34
Prevent Hidden Bootstrap 4 Modals to react events

Prevent Hidden Bootstrap 4 Modals to react events

I am trying to create a "Confirmation Modal" on deleting a row in a tableWhen the user wants to delete a row a Modal is shown (on click of a button) in which the user must type the username as a confirmation to delete it and click the delete...

60