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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

從另一個PHP文件中檢索數(shù)據(jù)

從另一個PHP文件中檢索數(shù)據(jù)

PHP
尚方寶劍之說 2021-04-06 13:15:50
用戶登錄后,我一直試圖將數(shù)據(jù)從一個php文件傳遞到另一個php文件。目標(biāo)是當(dāng)用戶注冊要重定向到顯示其統(tǒng)計信息的另一個頁面時(用戶名,金錢,紅寶石,鉆石)。index.php<?php include('server.php') ?><?php include('errors.php'); ?><div class="form-popupRegister" id="myRegForm">    <form method="post" action="server.php" class="form-containerReg">        <h1>Регистрирация</h1>        <label for="username"><b>Име</b></label>        <input type="text" name="username" placeholder="Въведете името на лейдито" value="<?php echo $username; ?>">        <label for="email"><b>Е-майл</b></label>        <input type="text" name="email" placeholder="Въведете e-mail" value="<?php echo $email; ?>">        <label for="password_1"><b>Парола</b></label>        <input type="password" placeholder="Въведете парола" name="password_1">        <label for="password_2"><b>Повторете Парола</b></label>        <input type="password" placeholder="Въведете парола повторно" name="password_2">        <button type="submit" class="btnReg" name="reg_user">Register</button>        <button type="button" class="btn-cancelReg" onclick="closeRegForm()">Close</button>    </form></div>index2.php<?php require('server.php') ?><!DOCTYPE html><html><head>  <meta charset="UTF-8">  <meta name="viewport" content="width=device-width, initial-scale=1">  <meta http-equiv="X-UA-Compatible" content="ie=edge">  <title>PwettyKittyPincesa</title>  <link href="./style.css" type="text/css" rel="stylesheet" /></head><body>    <div class="navWrapper">        <div class="statistics">            <div class="profilePicture" name="profilePicture">                <label class="profilePictureLabel" for="profilePicture"><b><?php echo $username; ?></b></label>            </div>            <div class="money" name="money">            <output name="money" for="money"><?php echo $money; ?></output>            </div>請檢查我的代碼并為我提供幫助。我已經(jīng)嘗試了很長時間,以至于我感覺自己將失去理智。我認為php中存在錯誤。
查看完整描述

1 回答

?
慕哥9229398

TA貢獻1877條經(jīng)驗 獲得超6個贊

除非您沒有在答案中顯示任何內(nèi)容,否則您實際上并沒有做任何事情來保存會話數(shù)據(jù)。


...

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

        $username = $_SESSION['username'];

        $level = $row['level'];

        $money = $row['money'];

        $diamond = $row['diamond'];

        $ruby = $row['rubin'];

    }

    header('location: index2.php');

...

在這里,通過傳遞標(biāo)頭,您正在執(zhí)行客戶端重定向,該重定向?qū)е聦⑿抡埱蟀l(fā)送到您的服務(wù)器。這意味著在請求1(index.php)中設(shè)置的變量將在請求2()中不可用index2.php。


您可能不想為這樣簡單的事情進行客戶端重定向。在不重新構(gòu)建代碼的情況下解決此問題的最簡單方法是將標(biāo)頭調(diào)用更改為包括


...

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

        $username = $_SESSION['username'];

        $level = $row['level'];

        $money = $row['money'];

        $diamond = $row['diamond'];

        $ruby = $row['rubin'];

    }

    include('index2.php');

...

(實際上不這樣做,請參見下面的更新)。


但是,您可能想考慮如何組織代碼。有include呼叫所有的地方可以迅速變得混亂和混淆。我建議研究一下PHP路由庫。周圍有一些,例如Klein。


最后,如果出于某種原因確實需要跨客戶端重定向保留數(shù)據(jù),則需要將其存儲在會話變量或數(shù)據(jù)庫中。這$_SESSION;陣列從讀/寫,你可以在其中存儲的數(shù)據(jù)應(yīng)在整個會議持續(xù)您獲取你的用戶名(與注意事項。使用數(shù)據(jù)庫或文件存儲在適當(dāng)?shù)臅r候)。有關(guān)更多信息,請參見PHP文檔。


更新:


所以,我只注意到你實際上是include荷蘭國際集團的server.php文件在您index2.php文件。在這種情況下,你不能include在index2.php在server.php文件的文件,因為這將是一個無限循環(huán)。


我不確定要推薦什么,但似乎您需要重組代碼,同時要記住,使用header調(diào)用重定向?qū)G失所有當(dāng)前PHP狀態(tài)(變量等)。最簡單的事情可能是只調(diào)用您的index2.php文件,讓它包含您的服務(wù)器文件,然后die如果有錯誤。如果成功執(zhí)行查詢,您的變量將可用。


因此,在以下范圍內(nèi)server.php:


if (count($errors) == 0) {

   ....

} else {

  die('Unsuccessful registration');

}


查看完整回答
反對 回復(fù) 2021-04-23
  • 1 回答
  • 0 關(guān)注
  • 153 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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