如何确保移动到java页面时php变量不会消失?

<?php

print "<td><a href=q.php?pcode=$pcode><img height=200 src=image/$pcode.jpg </a></td>";

?>

This is what I have written on my php page, once I click the image a prompt box will appear asking me for the quantity that I want the product, which is represented through the image.

<script type="text/javascript">

function typequantity () 
{
    q=prompt("Quantity?","");

    if (q!=0 && q!="" && q!=null )
    {   
        window.location.href = "http://localhost/buy.php?q="+q;
    }
    else 
    {
        window.location.href = "http://localhost/buy.php";
    }

}
</script>

<body onload="typequantity()">
</body>

However, the quantity does sends back, but the pcode is lost, and I need both of them.

I agree that your question is not well formatted but i understood, check this out.

<?php 
    echo '<a href="http://localhost/q.php?pcode='.$pcode.'" id="link" onclick="typequantity(this); return false;"><img src="image/pcode.jpg" height="200" /></a>';
?>

<script type="text/javascript">
function typequantity(obj)
{
    //Get the arg from the link
    arg = obj.getAttribute("href").split("=");

    q = prompt("Quantity?","");
    if (q!=0 && q!="" && q!=null ){   
        window.location.href = "http://localhost/buy.php?q=" + q + "&pcode=" + arg[1];
    }
    else 
    {
        window.location.href = "http://localhost/buy.php";
    }
}    
</script>

<body>
</body>

Next time be careful at your formatting.