PHP [SOLVED]: PHP mySQL Simple Echo from SELECT

PHP [SOLVED]: PHP mySQL Simple Echo from SELECT

Home Forums Scripting PHP Tutorials PHP [SOLVED]: PHP mySQL Simple Echo from SELECT

Tagged: ,

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #245551

    Cloudy Point
    Keymaster

    QuestionQuestion

    I am trying to create a simple echo from a SELECT from DB.

    It echos blank always.

    Here is the code:

    <?php
    $username = "xxxx";
    $password = "xxxx";
    $hostname = "xxxx";
    
    $conn = mysqli_connect($hostname, $username, $password, "xxxx");
    
    if(! $conn ) {
        die('Could not connect: ' . mysqli_error());
    }
    
    $user = $_GET['user'];
    $pass = $_GET['pass'];
    
    $sql = "SELECT id FROM 'users' WHERE user='$user' AND pass='$pass'";
    $retval = mysqli_query($conn, $sql);
    
    
    
    echo($retval);
    
    
    mysqli_close($conn);
    ?>
    

    It would be greatly appreciated if someone could help and tell me what I am doing incorrectly 🙂

    #245552

    Cloudy Point
    Keymaster

    Accepted AnswerAnswer

    Do you know if you are connected to the database or not? You could try changing a value to see if the error comes up or not.

    If thats not the issue this should work better:

    $host = 'xxxx';
    $user = 'xxxx';
    $pass = 'xxxx';
    $db = 'xxxx';
    $mysqli = new mysqli($host,$user,$pass,$db) or die($mysqli->error);
    
    $sql = "SELECT id FROM 'users' WHERE user='$user' AND pass='$pass'";
    $result = $mysqli->query($sql);
    
    while($row = $result->fetch_assoc()) {
       $whateverString = $row['cakes'];
    }
    echo $whateverString;
    

    Now lets say that you had a value in the mysql row called cakes that is equals to 5 then it will fetch that specific string from the row if the user and pass is correct.

    So the value above will output “5” if the mysql value ‘cakes’ is 5.

    Source: https://stackoverflow.com/questions/48030353/php-mysql-simple-echo-from-select
    Author: Sondre PvP
    Creative Commons License
    This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.