简体   繁体   中英

Mysqli_query not returning any variables

I'm currently trying to make a webpage that takes the users choice in the html form, and makes an sql query based on those choices(i am completely new to php), but when the query happens i get an empty page with only "my result:", and no result. I edited in the rest of the code, still stuck...

Thanks in advance.

example of one of my forms:

 <form action="phpkode.php" method="GET">
        <select name = "type">
            <option value= null>Type</option>
            <option value="Kylling">Kylling</option>
            <option value="Storfe">Storfe</option>
            <option value="Fisk">Fisk</option>
            <option value="Vegetar">Vegetar</option>
            <option value="Egg">Egg</option>
            <option value="Lam">Lam</option>
            </select>

php:

 <?php
$servername = "servername";
$username = "user";
$password = "password";
$conn = new mysqli($servername, $username, $password, "matdatabase" );


    if($_GET['type'] == null && $_GET['tid'] == null && $_GET['pris'] == null && $_GET['sunnhet'] == null) {
    $sql = mysqli_query($conn, "SELECT link FROM matdatabase.matrett ORDER BY RAND() LIMIT 1 ");
    }

$row = mysqli_fetch_assoc($sql);
echo $row;


?>

SQL database

From what you've posted, it lookes like only the type is being sent from the form. Make sure that the if-statement's condition is true.

Regarding your question's title: mysqli_query() returns a mysqli_object after a successful SELECT, SHOW, DESCRIBE, or EXPLAIN query.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM