1

I'm developing a website where people can vote on youtube videos.

In my toplist I have an upvote button. I generate it with php code, but on the first video it does not generate the form for the first button.

Here is the code:

echo "
    <tr>
      <th scope='row'>$i</th>
        <td>$title</td>
        <td>$vote</td>
        <td>
        <a style='color: #00bcd4;' href='https://www.youtube.com/watch?v=$url' target='_blank'>
          Watch
        </a>
      </td>
       <td>
         <form method='post' action='sendmusic.php'>
           <input value='https://www.youtube.com/watch?v=$url' type='hidden' name='url'>
           <input type='hidden' value='upvote' name='name'>
           <button type='submit' class='mdl-button mdl-js-ripple-effect mdl-js-button mdl-button--raised mdl-button--colored'>Upvote</button>
         </form>
       </td>
    </tr>

";
4
  • 1
    Possible duplicate of PHP Echo a large block of text Commented Jan 25, 2016 at 16:06
  • I think you're not showing all the relevant code as you are using $i which is most likely previously defined. Commented Jan 25, 2016 at 16:14
  • In the source does it show any of the form? Commented Jan 25, 2016 at 16:14
  • @Billy in the source at the first video it shows the whole code without the form, but after that it has the form Commented Jan 25, 2016 at 16:57

1 Answer 1

3

why wouldn't you just do:

for ($i = 0; $i <= 10; $i++):
?> <!-- close php -->
    <tr>
      <th scope='row'><?php echo $i ?></th>
        <td><?php echo $title ?></td>
        <td><?php echo $vote ?></td>
        <td>
        <a style='color: #00bcd4;' href='<?php echo "https://www.youtube.com/watch?v=$url" ?>' target='_blank'>
          Watch
        </a>
      </td>
       <td>
         <form method='post' action='sendmusic.php'>
           <input value='<?php echo "https://www.youtube.com/watch?v=$url" ?>' type='hidden' name='url'>
           <input type='hidden' value='upvote' name='name'>
           <button type='submit' class='mdl-button mdl-js-ripple-effect mdl-js-button mdl-button--raised mdl-button--colored'>Upvote</button>
         </form>
       </td>
    </tr>
<!-- open php -->
<?php
endfor;
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, but it does not write ot the form for the first time

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.