Member 14729284 Ответов: 1

Как передать переменную с одной страницы на другую с помощью PHP?


Я очень новичок в PHP и MySQL, и у меня возникли проблемы с отправкой значения переменной на другой php. Ниже приведено page1.php и еще page2.php.

Что я уже пробовал:

Вот это да page1.php:


<!DOCTYPE html>
<html>
<head>
<title> Menu </title>
<link rel="stylesheet" href="style.css" >
</head>
<body>
<?php
$conn = mysqli_connect('localhost', 'root', ' ' );
mysqli_select_db($conn, 'mydb');


// Start the session
session_start();

// Set session variables
$_SESSION["Name of disorders"] = "Schizophrenia";
$_SESSION["Name of disorders"] = "Bipolar disorder";
$_SESSION["Name of disorders"] = "Major depressive disorder"; 



$sql1= "SELECT Data FROM `menu` WHERE `Data_type` = 'Disorder' ";
$sql2= "SELECT Data FROM `menu` WHERE `Data_type` = 'Tissue' ";
$sql3= "SELECT Data FROM `menu` WHERE `Data_type` = 'Data type' ";

if ($result1 = mysqli_query($conn, $sql1));
{
	
echo "<table>";
        echo "<tr>";
		    echo "<th><a href='Home.php'>Home</a></th>";
			echo "</tr>";
echo "</table>";
echo "<br>";	
echo "<table>";		
			echo "<tr>";
	         echo "<th>Psychiatric disorders</th>";
		echo "</tr>";	 
echo "</table>";

}
 while($row = mysqli_fetch_array($result1))
{
echo "<table>";
	    echo "<tr>";
		    echo "<td><a href='disorder.php?disorder="    . $row['Data' ] .  " '>"    . $row['Data'] .  "</a></td>";
		echo "</tr>";
echo "</table>";
}
echo "<br>";


if ($result2 = mysqli_query($conn, $sql2));
{
echo "<table>";
        echo "<tr>";
	        echo "<th>Tissue type</th>";
		echo "</tr>";	 
		echo "</table>";

}
while($row = mysqli_fetch_array($result2))
{
echo"<table>";
	    echo "<tr>";
		echo "<td><a href='tissue.php?tissue="    . $row['Data' ] .  " '>"    . $row['Data'] .  "</a></td>";
		echo "</tr>";
echo "</table>";
}
echo "<br>";

if ($result3= mysqli_query($conn, $sql3));
{
echo "<table>";
        echo "<tr>";
	        echo "<th>Expression type</th>";
		echo "</tr>";	 
echo "</table>";

}
while($row = mysqli_fetch_array($result3))
{
echo "<table>";
	    echo "<tr>";
		   echo "<td><a href='data_type.php?datatype="    . $row['Data' ] .  " '>"    . $row['Data'] .  "</a></td>";
		echo "</tr>";
echo "</table>";
}
echo "<br>";

echo "<table>";
    echo "<tr>";
		    echo "<th><a href='Contact_us.php'>Contact us</a></th>";
	echo "</tr>";
echo "</table>";
?>
</body>
</html>


Вот это да page2.php:

<?php 
echo "<!DOCTYPE html>";
echo "<html>";
echo "<head>";
echo "<title> Psychiatric Disorders</title>";

 
include ('menu.php');

$conn = mysqli_connect('localhost', 'root', '');
mysqli_select_db($conn, 'mydb');


session_start();

// Echo session variables that were set on previous page
echo "  " . $_SESSION["Name of disorders"] . ".<br>";


//$row ['Data'] = $_GET ['Data' ];

$sql = "SELECT * FROM `psychiatric disorders raw datasets` WHERE `Name of disorders` = '  '  ";
if ($result = mysqli_query($conn, $sql));
{	
        echo "<table border='1' cellpadding='2' cellspacing='2'>  ";
	       echo "<tr>";
			    echo "<th>Accession ID</th>";
                echo "<th>Title</th>";
                echo "<th>Abstract</th>";
				echo "<th>Sample size</th>";
				echo "<th>Tissue type</th>";
				echo "<th>PMID</th>";
				echo "<th>Platform ID</th>";
				echo "<th>Platform details</th>";
				echo "<th>Raw data</th>";
            echo "</tr>";
		while($row = mysqli_fetch_array($result))
		{
			echo "<tr>";
			    echo "<td>" . $row['Accession ID'] . "</td>";
                echo "<td>" . $row['Title'] . "</td>";
                echo "<td>" . $row['Abstract'] . "</td>";
				echo "<td>" . $row['Sample size'] . "</td>";
				echo "<td>".  $row['Tissue type']. "</td>";
				echo "<td>" . $row['PMID'] . "</td>";
				echo "<td>" . $row['Platform ID'] . "</td>";
				echo "<td>" . $row['Platform details'] . "</td>";
				echo "<td>" . $row['Raw data'] . "</td>";
		    echo "</tr>";
        }
        echo "</table>";
    }
echo "</html>";
echo "</body>";
?>

1 Ответов

Рейтинг:
2

CPallini

Ты Гугл за это?
Отправная точка: Передача переменной между страницами в PHP[^].


Member 14729284

@CPallini Да,я погуглил его и попробовал код сеанса выше, вы можете его увидеть, но он не работает.

CPallini

Взгляните также на эту страницу:
https://stackoverflow.com/questions/871858/php-pass-variable-to-next-page

Member 14729284

Я пробовал использовать методы GET,POST, making SESSION variable и Cookies, но ни один из них не работает.