【问题标题】:How to pass a variable from one page to another with PHP?如何使用 PHP 将变量从一个页面传递到另一个页面?
【发布时间】:2019-03-06 09:31:37
【问题描述】:

我支持数据库,如何将变量从一个页面共享到另一个页面?

我的页面choose.php 在加载时会生成以数据库表的字段值作为值的按钮。 我必须确保在单击按钮时: - 为我保存一个表格数据(“id”) - 我被重定向到另一个页面 - 在我被重定向以获取变量并将其放入查询的页面上

有可能吗?如果有怎么办?

<!DOCTYPE html>
<?php 
	session_start();
    if(!isset($_SESSION["username"])){
    	header('location: ../index.php');
    }else
    {
    
?>
<?php
$servername = "localhost";
$username = "";
$password = "";
$dbname = "";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$sql = "SELECT idCantiere,nomeCantiere,codiceCommessa,indirizzoCantiere FROM Cantiere";
$result = $conn->query($sql);
echo'<h1> <font face="verdana" color="green">Quale Cantiere desideri Modificare?</font> </h1>';
if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
		
		echo'<br><br><br>';
		echo'<a href="#" class="myButton" alt="">' . $row["nomeCantiere"] . '</a>';
      
		
		
    }
	echo'<br><br><br>';
	echo '<a href="../pagineHtml/inserimento/inserimentoGenerale/inserimentoCantiere.php" class="myButton" alt="Nuovo Cantiere +">Nuovo Cantiere +</a>';
	
} else {
    echo "0 results";
}
$idCantierePerSelect = $_POST["idCantiere"];
global = $idCantierePerSelect;

echo $idCantierePerSelect;



$conn->close();
?>

目前我只设法自动加载按钮... 我想把“idCantiere”,这是我必须从一个表转到另一个表的字段,全局

【问题讨论】:

标签: php html mysql web-applications


【解决方案1】:

在页面之间传递变量的一种方法是在 URL 中“发布”它。

这个问题已经回答过了,看这里。

Passing multiple variables to another page in url

总之补充:

<a href="index.php?idCantiere=".$idCantiere.""></a>

然后在 index.php 处做

$idCantiere = $_GET['idCantiere']

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-17
    • 1970-01-01
    • 1970-01-01
    • 2013-02-13
    • 1970-01-01
    • 2012-12-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多