第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

php 預(yù)準(zhǔn)備語(yǔ)句不顯示用戶數(shù)據(jù)

php 預(yù)準(zhǔn)備語(yǔ)句不顯示用戶數(shù)據(jù)

PHP
有只小跳蛙 2022-09-17 17:52:31
我設(shè)置了一個(gè)輸入表單,在其中我使用 SELECT 函數(shù)在表中搜索現(xiàn)有用戶,因此它將顯示用戶的姓名和電子郵件。但是當(dāng)我嘗試時(shí),即使表中有一個(gè)名為John的用戶,我也會(huì)得到“沒有名為John的用戶!”。為什么準(zhǔn)備好的聲明不起作用?添加準(zhǔn)備語(yǔ)句.php<?php    include_once 'includes/db_connect.php';?><!DOCTYPE html><html><head><title>SCIENCE FAIR</title><link rel="stylesheet" href="style.css">    <section class ="container grey-text">    <form class="white" action="addpreparedstatements.php" method="POST">    <tr>        <label>First Name:</label>        <td><input type="text" name="firstname" placeholder="First Name"></td></br>    </tr>        <div class="center">            <td colspan="2"><input type="submit" name="submit" value="Submit"></td>        </div>    </form></section></html><?php    $firstname = mysqli_real_escape_string($conn, $_POST['firstname']);    $sql = "SELECT * FROM usersthree WHERE id=?";    $stmt = $conn->prepare($sql);     $stmt->bind_param("s", $id);    $stmt->execute();    $result = $stmt->get_result(); // get the mysqli result    $user = $result->fetch_assoc(); // fetch data       $queryResult = mysqli_num_rows($result);        if ($queryResult > 0) {            while ($row = mysqli_fetch_assoc($result)) {                echo "<div>                <p>".$row['name']."<p>                <p>".$row['email']."<p>                </div>";            }        } else {            echo "No users with name $firstname!";        }?>
查看完整描述

1 回答

?
慕尼黑8549860

TA貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超11個(gè)贊

綁定到查詢的變量未初始化。$id


您想要搜索“名字”,因此您需要在查詢中使用變量$firstname。


// Check if formular is send and $_POST['firstname'] is set

if (isset($_POST['firstname'])) {

    // Escaping is not neccessary because you use prepared statements!

    $firstname = $_POST['firstname'];

    $sql = "SELECT * FROM usersthree WHERE firstname=?";

    $stmt = $conn->prepare($sql); 

    $stmt->bind_param("s", $firstname);

    $result = $stmt->get_result(); // get the mysqli result

    $queryResult = mysqli_num_rows($result);


    if ($queryResult > 0) {

        while ($row = mysqli_fetch_assoc($result)) {

            echo "<div>

            <p>".$row['name']."<p>

            <p>".$row['email']."<p>

            </div>";

        }

    } else {

        echo "No users with name $firstname!";

    }

}


查看完整回答
反對(duì) 回復(fù) 2022-09-17
  • 1 回答
  • 0 關(guān)注
  • 87 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)