开发者

HTML Button list within PHP "For Loop" not working

I seem to be having a very simple problem but I can't wrap my head around the issue. Thanks in advance for any help you may have.

First, here is 开发者_如何学运维a description of the code: The following snippet of code is from a user's activity page. This snipped displays all bids that have been placed on a user's "canvas."

<table  width="400" align=center frame=below>

    <ul>
    <?php for ($j = 0 ; $j < $numBids ; ++$j) { $cbid= mysql_fetch_row($bids); ?>   
     <li><strong>$<?php echo "$cbid[2]"; ?>.00 </strong> by <a href="profile.html?view=<?php echo "$cbid[4]"; ?>"><?php $name=getUser($cbid[4]); echo "$name"; ?></a>
     <br/>"<?php echo "$cbid[3]"; ?>"<br/>

     <p align=CENTER>

     <!-- Message Artist-->
     <form method="post" action="messages.html?msg=<?php echo $cbid[4]; ?>" >    
    <input type="submit" name="message" value="Message Artist" > 
    </form>

    <!-- Accept Bid-->
     <form method="post" action="contract.html?bid=<?php echo "$cbid[0]"; ?>" class="login-form">                       
    <input type="submit" value="ACCEPT BID!" > 
    </form>

    </p>

     </li>                                  
    <?php   } ?>                                    
   </ul>

If $numBids = 3, The html output of this code is:

    <ul>

     <li><strong>$150.00 </strong> by <a href="profile.html?view=169&sid=d0ba8340cdb156c233baf364960ac3e9">Artist Name</a>
     <br/>"I would like to paint this in acrylic."<br/>

     <p align=CENTER>
     <!-- Message Artist-->
     <form method="post" action="messages.html?msg=151" ><input type="hidden" name="sid" value="d0ba8340cdb156c233baf364960ac3e9" />    
    <input type="submit" name="message" value="Message Artist" > 
    </form>
    <!-- Accept Bid-->
     <form method="post" action="contract.html?bid=76" class="login-form"><input type="hidden" name="sid" value="d0ba8340cdb156c233baf364960ac3e9" />                       
    <input type="submit" value="ACCEPT BID!" > 
    </form>
    </p>

     </li>                                  

     <li><strong>$150.00 </strong> by <a href="profile.html?view=169&sid=d0ba8340cdb156c233baf364960ac3e9">Artist Name</a>
     <br/>"I would like to paint this in acrylic."<br/>

     <p align=CENTER>
     <!-- Message Artist-->
     <form method="post" action="messages.html?msg=151" ><input type="hidden" name="sid" value="d0ba8340cdb156c233baf364960ac3e9" />    
    <input type="submit" name="message" value="Message Artist" > 
    </form>
    <!-- Accept Bid-->
     <form method="post" action="contract.html?bid=72" class="login-form"><input type="hidden" name="sid" value="d0ba8340cdb156c233baf364960ac3e9" />                       
    <input type="submit" value="ACCEPT BID!" > 
    </form>
    </p>

     </li>                                  

     <li><strong>$150.00 </strong> by <a href="profile.html?view=169&sid=d0ba8340cdb156c233baf364960ac3e9">Artist Name</a>
     <br/>"I would like to paint this in acrylic."<br/>

     <p align=CENTER>
     <!-- Message Artist-->
     <form method="post" action="messages.html?msg=169" ><input type="hidden" name="sid" value="d0ba8340cdb156c233baf364960ac3e9" />    
    <input type="submit" name="message" value="Message Artist" > 
    </form>
    <!-- Accept Bid-->
     <form method="post" action="contract.html?bid=70" class="login-form"><input type="hidden" name="sid" value="d0ba8340cdb156c233baf364960ac3e9" />                       
    <input type="submit" value="ACCEPT BID!" > 
    </form>
    </p>

     </li>                                  

   </ul>

A live test version of the page has been set up: http://www.canvasmatch.com/test/activity.html.


Now to the problem:

If a user clicks the "Message Artist" button, the user jumps to a messages page where the can send a message to the artist, obviously. This button works for all bids EXCEPT on the first one. If you were to click the first "Message Artist" button it would just refresh the page, incorrectly. However if you clicked the second "Message Artist" button it would jump to messages.html appropriately. If there were say 6 bids, all of the "Message Artist" buttons would work EXCEPT the first one.

The weird thing for me is that all "Accept Bid" buttons work, even the first one.

Has anybody experienced anything like this before? Any thoughts on what I should be looking for? Do you need the entire html file to find the problem?

I appreciate any help you can provide!

Thanks,

Jake


Basically, when you inspect the element with Firebug you'll see it's not encapsulated within a form. Something strange is going on because the HTML actually looks fine for that particular element. The rest of the document is full of errors though, so while I can't pinpoint it directly, I'd recommend first at least fixing the majority of the errors that can be found by doing a W3C Validation test. I can almost guarantee that it'll work once these are fixed.

http://validator.w3.org/check?uri=http%3A%2F%2Fwww.canvasmatch.com%2Ftest%2Factivity.html


It looks like you need quotes around $cbid[4]

Current:

<form method="post" action="messages.html?msg=<?php echo $cbid[4]; ?>" >

Change to

<form method="post" action="messages.html?msg=<?php echo "$cbid[4]"; ?>" >


If $numBids = 3, The html output of this code is:

Are you setting $numBids to 3 each iteration? If it is a comparison, it should be $numBids == 3 but it's a bit ambiguous because the snippet is not in the code block.


The issue is the increment for $j. The for statement should look like:

for ($j = 0 ; $j < $numBids ; $j++)

++$j increments first then does the loop so instead of the first time being 0, it ends up 1. The quotations around the variable in the php script is not necessary.

I do have a question, Why are you using a for loop instead of a while loop with a counter defined before the loop and an increment at the end?

EDIT

Just remembered had an issue with a gallery that I was using forms on and the first one did not work. To fix, I had to add a random string name to each one. Try adding a name to each form tag with a random generated string or number.

Example:

 <form method="post" action="messages.html?msg=151" class="login-form" name="fEd5t89">

Edit - Working

After looking at the files it was found that this was a nested <form>. After removing the wrapping <form>, the page started working properly.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜