0
<!DOCTYPE html>
<html>
<head>
    <title> Search </title>
</head>

    <body>
    <h1>Please enter in the desired search criteria</h1>
    <form>
        Customer's First name:
        <br>
        <input type="text" name="Fname">
        <br>
        Customer's Last name:
        <br>
        <input type="text" name="Lname">
        <br> <br>
        Order ID:
        <br>
        <input type="text" name="OrderID">
        <br> <br>
        Volunteer's First Name:
        <br>
        <input type="text" name="VolFName">
        <br>
        Volunteer's Last Name:
        <br>
        <input type="text" name="VolLName">
        <br><br>
        Item ID:
        <br>
        <input type="text" name="ItemName">
        <br><br>
        <input type="submit" name="submit_search" value="submit_search">
    </form>
    </body>
<?php
    $fName = $_POST['Fname'];
    $lName = $_POST['LName'];
    $orderID = $_POST['OrderID'];
    $VolFName = $_POST['VolFName'];
    $VolLName = $_POST['VolLName'];
    $itemName = $_POST['ItemName'];

    //Connect to server
    $conn = new mysqli('localhost', 'user', 'password', 'KittenMittens');
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    }
    echo "Connected successfully";
    /*
    $sql = "SELECT * FROM Customer where ('$fName' = fName and '$lName' = lName)";
    $rs = $conn->query($sql);
            //echo $rs;
    echo "<p align='center'><font color='red'><u>Results: </u></font></p>";
    echo $rs;
    if ($rs -> num_rows > 0){
        while($row = $rs -> fetch_assoc($rs)){
            echo $rows;
        }
    }
    */
    $sql = "SELECT * FROM KittenMittens.Customer";
    $result = $conn->query($sql);
    var_dump($result);
    while($row = $result->fetch_assoc()){
        echo $row['itemname'];
    }
    $conn->close();
?>
</html>

I've been looking at different tutorials from W3Schools and other helpful guides on how to return the results from a query from the database. When I run var_dump($result) I get: object(mysqli_result)#2 (5) { ["current_field"]=> int(0) ["field_count"]=> int(9) ["lengths"]=> NULL ["num_rows"]=> int(1) ["type"]=> int(0) }, but I am not able to get anything to echo on the screen. I have verified there is data within the table I am accessing, and the connection is verified.

Any help in figuring out why I am not able to get any data to be echoed would be much appreciated. Thank you!

CaSrBa
  • 13
  • 3

1 Answers1

0

You need to echo out within the <body></body> tags

chriswirz
  • 278
  • 1
  • 9
  • @chriswirz That solved the problem, could you possibly explain why that is needed though? – CaSrBa Apr 06 '16 at 17:37
  • It's too bad the answerer didn't show you some code to accomplish this, but it is basic HTML. Anything you want to display has to be in the body of the HTML. – Jay Blanchard Apr 06 '16 at 17:38
  • @Jay Blanchard Thank you for explaining that. I've been trying to learn how to use HTML and PHP, and that has been one of my biggest questions as to where the "" is supposed to go within it to make it function together. – CaSrBa Apr 06 '16 at 17:40
  • 1
    I just tested something similar in my machine with echos after `

    ` with a DB query, so I can't see how OP's code wouldn't. But hey, more power to you if that's what it took. But I am baffled.

    – Funk Forty Niner Apr 06 '16 at 17:41
  • The PHP code can go anywhere, for instance you could run the query early on and then put your display code in the body. There are lot's of options. I'd recommend an online interactive tutorial, like codecademy.com, to get the basics down @xXNathan360Xx – Jay Blanchard Apr 06 '16 at 17:41
  • @Fred-ii- That was the only edit I made to my code and it was successfully being displayed, so I am not sure what I did within my code that would make it that way, maybe something else is at play. – CaSrBa Apr 06 '16 at 17:43
  • @xXNathan360Xx I have no idea. I'd have to take your code and setup a db just for it and try it for myself. What browser and version are you using? That could have something to do with it. – Funk Forty Niner Apr 06 '16 at 17:44
  • @Fred-ii- I am currently running it on Version 49.0.2623.110 (64-bit) of Chrome – CaSrBa Apr 06 '16 at 17:45
  • @xXNathan360Xx That could be why then. It's particular in its own little world. Try it out on FF (the latest) and you'll see it will work. Do that with your old code. – Funk Forty Niner Apr 06 '16 at 17:47
  • @Fred-ii- Alright, I will check it out. Thank you for the help! – CaSrBa Apr 06 '16 at 17:49
  • @xXNathan360Xx You're welcome. Let me know either way. – Funk Forty Niner Apr 06 '16 at 17:50
  • @Fred-ii- Sorry to extend the chat, I tried the old code in both and it worked, so I am curious if in the process of editing my code from the suggestions, I had a syntax error and it got fixed. Anyways thank you. – CaSrBa Apr 06 '16 at 18:00