1

I want to select a row from my users’ table 'tbl_login' in my database with the following php script:

<?php

    include 'config.inc.php';

    $conn = mysqli_connect($servername, $username, $password, $dbname);

    $email = $_POST["email"];

    $sql = "SELECT email, firstname, lastname, location 
        FROM tbl_login
        WHERE email = '$email'";

    $res = mysqli_query($conn,$sql);

    $result = array();

    while($row = mysqli_fetch_array($res)){
        array_push($result,
        array('email'=>$row[0],
              'firstname'=>$row[1],
              'lastname'=>$row[2],
              'location'=>$row[3]
              ));
    }

    if ($conn->query($sql) === TRUE) {
        echo "Selected row successfully";
    } else {
        echo "Error: " . $sql . "<br>" . $conn->error;
    }

    echo json_encode(array("result"=>$result));

    mysqli_close($conn);

?>

My problem is that I’m not sure how to write this part:

$email = $_POST['email']; // <--- This.

$sql = "SELECT email, firstname, lastname, location 
        FROM tbl_login
        WHERE email = '$email'"; // <--- And this.

If I’m trying without the $_POST and with just a hardcoded string like 'Luke', it works, so I figured my problem is on the $_POST.

My others scripts are done this way and they all work, if you could enlighten me on why this is not working, I would be extremely grateful, as I've been working on this for a few hours already. Thanks a lot in advance, Charles.

1 Answer 1

1

Try That

$email = $_REQUEST["email"];

$sql="SELECT email, firstname, lastname, location FROM tbl_login WHERE email='$email'";
Sign up to request clarification or add additional context in comments.

1 Comment

Hey thanks alot, it worked right away. Have a nice day !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.