[英]the html not showing value of php(UPDATED)
更新:我在 PHP mailuid
中有一個變量,我想在我的 HTML 中顯示該變量。 它顯示錯誤 mailuid 的值在網頁上未定義。 如何將高度值顯示到 html 頁面?
index.php
<?php
require "header.php";
?>
<main>
<link rel="stylesheet" type="text/css" href="styl.css">
<div class="wrapper-main">
<section class="section-default">
<h2><?php echo "$mailuid" ?></h2>
<?php
?>
</section>
</div>
</main>
<?php
require "footer.php";
?>
loginbackend.php
<?php
if(isset($_POST['login-submit'])) {
require 'db.php';
$mailuid = $_POST['mailuid'];
$password = $_POST['pwd'];
if (empty($mailuid) || empty($password)) {
header("Location: ./index.php?error=emptyfields");
exit();
} else {
$sql = "SELECT * FROM users WHERE uidUsers=? OR emailUsers=?;";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
header("Location: ./index.php?error=sqlerror");
exit();
} else {
mysqli_stmt_bind_param($stmt, "ss", $mailuid, $mailuid);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
if ($row = mysqli_fetch_assoc($result)) {
$pwdCheck = password_verify($password, $row['pwdUsers']);
if($pwdCheck == false) {
header("Location: ./index.php?error=wrongpwd");
exit();
} else if ($pwdCheck == true) {
session_start();
$_SESSION['userId'] = $row['idUsers'];
$_SESSION['userUid'] = $row['uidUsers'];
$username = substr($mailuid, 0, strpos($mailuid, "@"));
header("Location: ./index.php?login=success".$username);
exit();
} else {
header("Location: ./index.php?error=wrongpwd");
exit();
}
} else {
header("Location: ./index.php?error=nouser");
exit();
}
}
}
} else {
header("Location: ./signup.php");
exit();
}
您犯的錯誤:我認為您混淆了 forms 和文件,包括帖子的工作方式。
讓我解釋一下:表單將數據發送到服務器,然后將其推送到 $_POST 全局變量中。 您可以通過回顯或轉儲來輕松讀取和使用這些數據。
這是您應該做的:在這種情況下,您的數據值將為空,因為您沒有向其傳遞任何內容。
您可以通過創建一個表單並將其傳遞給您的 PHP 文件來解決此問題。
您也可以只需要您的 php 腳本。
通常您會將 data.php 放入您的操作中,但由於您希望在輸入表單之前使用該變量,因此您必須先包含它。
索引.html
<?php require 'data.php'; ?>
<form method="POST" action="">
<h1>Height: <?=$height?></h1>
<input type="text" placeholder="Enter the height..." name="height">
<input type="submit" name="submit" value="Submit">
</form>
數據.php
<?php
if (!empty($_POST)) {
$height = $_POST['height'];
} else {
$height = 0; //Default height
}
如果我沒有正確回答您的問題,我深表歉意。
============================================
選項 B,如果這是您的意思,就是這樣做:
索引.html
<body>
<div class="container">
<?php
require 'data.php'; //Get the data.php file so we can use the contents
?>
<h1><?php echo $height; ?></h1>
</div>
</body>
數據.php
<?php
$height = 100; //Height variable
根據您的最新評論:
要從 URL(GET 參數)獲取 mailuid,請將以下代碼添加到您的 index.php
<?PHP
require "header.php";
$mailuid = !empty($_GET['mailuid']) ? $_GET['mailuid'] : null;
// You can also specify the default value to be used instead of `null` if the `mailuid` is not specified in the URL.
?>
<main>
<link rel="stylesheet" type="text/css" href="styl.css">
<div class="wrapper-main">
<section class="section-default">
<h2><?php echo "$mailuid"?></h2>
</section>
</div>
</main>
<?php
require "footer.php";
?>
從 PHP7 你可以使用
$mailuid = $_GET['mailuid'] ?? null;
代替
$mailuid = !empty($_GET['mailuid']) ? $_GET['mailuid'] : null;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.