2

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

3
  • It would be great to see the HTML this outputs to see if there are any obvious errors there. Commented Oct 4, 2011 at 4:05
  • Thanks Christian, I added it above. Commented Oct 4, 2011 at 4:17
  • send me your php script to [email protected] so i can look at it in full detail. so i can test/edit and give you the exact cause. Commented Oct 4, 2011 at 6:16

4 Answers 4

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you very much. I haven't actually used validator.w3.org before but this definitely helps highlight some of the issues. In particularly, we were using a <form> to define a CSS element which resulted in nested forms.
Awesome! It's helped me a lot over the years, glad it was able to help you too :)
0

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]"; ?>" >

1 Comment

Thanks. I added the quotes but that didn't fix the issue. The first "Message Artist" button is still a dead link.
0

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.

1 Comment

No, I am not setting $numBids to 3. I simply wrote that out for reference. I could post the entire php file as well if that would be helpful (and not overwhelming).
0

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.

10 Comments

The increment order doesn't solve the problem, if there are 3 bids placed it will still display all 3. Even if that was the problem I don't see how it would cause the first button to be a dead link. Could the problem reside in the fact that I'm not using a while loop?
it is possible but it may not help, if the data is the same for each one. do you have a test page that I can look at something live.
I added a live test version. Please see the link above, below the html output code
In your test the first message button has no form elements. I would check the varibles that are being passed by echoing them first, at the beginning of the for loop. Can you add an echo of the varibles used to create the form and turn on error reporting using error_reporting(E_ALL);?
I added error_reporting(E_ALL); but nothing new has shown up. I am not passing any variables through the form. I am simply using the button as a hyperlink. What confuses me is that the code for the first "Message Artist" button is identical to the second button, but the first doesn't work.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.