this is the code used to get the information from the database, the images I have taken off the echo statement for the time being, and just the name of the product. When I click on the product name it sends me to cart.php and should pass the value in the URL it shows in the browser when I hover over the text but when i click it send me to cart.php and just shows a blank page
$product_types = get_all_subjects2();
while($products = mysql_fetch_array($product_types))
{
$name = $products['name'];
$address = $products['image_location'];
$description = $produ开发者_StackOverflow社区cts['description'];
//echo $name;
echo '<ul>';
echo "<li><a href=\"http://localhost/project/cart.php?subj=" . urlencode($products["name"]) .
"\">{$products["name"]}</a></li>";
the code used to see if value isset
<?php
if (isset($_POST['subj']))
{
$a = $_POST['subj'];
echo $a;
}
else {
echo"error";
}
?>
The parameters passed via URL are in $_GET
and not in $_POST
:
$_GET
An associative array of variables passed to the current script via the URL parameters.
$_POST
is only for parameters passed by HTTP POST method.
So try $_GET['subj']
instead.
You're checking the PHP $_POST but are sending the data through URL.
If you're sending information through the URL you need to get at it through $_GET
<?php
if (isset($_GET['subj'])) {
$a = $_GET['subj'];
echo $a;
} else {
echo"error";
}
?>
精彩评论