Click here to Skip to main content
15,911,789 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm very new to PHP and MySQL, and I'm having trouble sending the value of a variable to another php. Below given page1.php and page2.php.

What I have tried:

Here is a 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>


Here is a 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>";
?>
Posted
Updated 24-Feb-20 21:17pm
v4

1 solution

Did you Google for that?
A starting point: Passing variable between pages in PHP[^].
 
Share this answer
 
Comments
Member 14729284 25-Feb-20 3:13am    
@CPallini Yes,I googled it and I've tried SESSION code above you can see it but it's not working.
CPallini 25-Feb-20 3:30am    
Have a look also at this page:
https://stackoverflow.com/questions/871858/php-pass-variable-to-next-page
Member 14729284 25-Feb-20 4:02am    
I've tried by GET,POST, making SESSION variable and Cookies method but none of them are working.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900