开发者

form text-input unwanted redirection on click

Please help, I can't understand why the code below keeps bringing me to viewcart.php when I click on the textbox that is used to input qty to buy, I made sure to close all the anchor tags in the page. I even removed all the links to viewcart.php but no luck:

<form name="cx" method="get" action="viewcart.php?action=add&id=<?php $pid; ?>">        
    <?php

        while($row=mysql_fetch_assoc($result)){
        $pid=$row['PID'];
        ?>
            <tr>
                <td><?php echo $row['PID']; ?></td>
            <td><a href="viewprod.php?prodname=<?php $row['PRODUCT']; ?>"> <?php echo $row['PRODUCT']; ?></a></td>

                <td><?php echo $row['CATEGORY']; ?></td>
                <td><?php echo $row['P_DESC']; ?></td>
                <td><?php echo $row['QTYHAND']; ?></td>
                <td><?php echo $row['S_PRICE']; ?></td>

                <input type="hidden" value="<?php echo $row['QTYHAND']; ?>" name="qoh[]"/>

                <input type="hidden" value="<?php echo $row['S_PRICE']; ?>" name="sprice[]"/>


                <?php echo "<td><a href=\"viewcart.php?action=add&id=$pid\"><img src=\"../img/system/add-icon.png\"></a></td>"; ?>
                <td><input type="checkbox" name="sc[]" id="<?php echo $row['PID'开发者_Python百科];?>" value="<?php echo $row['PID']; ?>"></input></td>
                <td><input type="text" name="qbuys[]" value="" id="qb"></input></td> <!--when I click on this, it seems like I'm clicking on a link to viewcart.php -->

</table>
<input type="submit" value="submit"></input>
</form>   

I removed some of the code which I don't think is useful in solving this problem. Please help. Thanks.


Your code has two issues. YOu're not echoing the $pid and you have a scoping error.

<form name="cx" method="get" action="viewcart.php?action=add&id=<?php $pid; ?>">

You need to add an echo:

<form name="cx" method="get" action="viewcart.php?action=add&id=<?php echo $pid; ?>">

Also, $pid doesn't exists until you're inside the while loop so you'll always be echoing '':

 // $pid == null;
<form name="cx" method="get" action="viewcart.php?action=add&id=<?php $pid; ?>">


<?php
    while($row=mysql_fetch_assoc($result)){
    $pid=$row['PID']; // NOW $pid has a value
?>

If you view the source of this page you should see:

 <form name="cx" method="get" action="viewcart.php?action=add&id=">

Notice the empty id. This would keep sending you back to viewcart.php


You are not echoing your $pid into the form action.

This means that when you submit your form it is not going where you expect.

action="viewcart.php?action=add&id=<?php echo $pid; ?>"

or

action="viewcart.php?action=add&id=<?=$pid?>"

This second examle will only work if your server has short tags enabled.


Rather than looking at the PHP code that generates the page, i would suggest loading the page in your browser, and then clicking "view source". That way you can see exactly what code is being generated, then work back from there to identify which statement is going wrong.

However, I would suggest looking at the following line:

<td><a href="viewprod.php?prodname=<?php $row['PRODUCT']; ?>"> <?php echo $row['PRODUCT']; ?></a></td>

There is no echo on the 'Product' property.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜