3

I Have table on browser Like This

  Name  | Action        |
________________________
Septiyo | Edit | Delete |
Fahmi   | Edit | Delete | 
Tejo    | Edit | Delete |

For Edit, usually I use link like this

  echo "<a href='edit.php?ID=$data['ID']'>Edit</a>";

With link, I can Include the ID variable and send to other Page.

The question is, if I change The Link with Button html. How can I include the variable?

My Button like this

 echo  "<input type='button' value='Edit' onclick='window.location=edit.php?ID=$data['ID']'>";

and it not Work.

Can anyone Help me?

Im very Appreciated your Answer.

Thanks.

2 Answers 2

4

Why not wrap your button in an <a> with the href set to the php page?

Like so:

echo <a href=yourPage.php><input type="button" value="Edit"></a>

A better option to consider might be taking out the input and styling the link to look like a button. It is standards compliant as well, where the other option may not be.

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

3 Comments

a elements may not have interactive content descendants which includes input
@Uchsun Thanks. :) Would you mind giving me an upvote as well? :)
If you go this way, why use a button at all? You might as well style the link so that it appears as a button.
2

Do as this:

<a href='edit.php?ID=<?php echo $data['ID']; ?>'>Edit</a>

PHP is processed on the server side. So, it must know that the code you are writing is php and it knows when you put it inside the php tags <?php //php code ?>

That was just pointed the answer for the OP would be:

For you send data through a button you have some ways:

  • Call a function to do the redirection
  • put the value in a form and submit it.

    With a form it would be:

    <form action="edit.php" method="post">
       <input type="hidden" name="ID" value="<?php echo $data['ID']; ?>">
       <input type="submit" value="Send">
    </form>
    

    Another way would be through some javascript function:

    <input 
      type="button" 
      onclick="javascript:window.open('edit.php?ID=<?php echo $data['ID']; ?>','','');">
    

    And one more:

    <script>
         function sendValue(id){
             window.location='edit.php?ID=' + id;
         }
    </script>
    <input 
      type="button" 
      onclick="javascript:sendValue('<?php echo $data['ID']; ?>')>
    
  • 2 Comments

    Oh yes Of course. I forget it. My COde inside the PHP so the code is inside the Echo
    @JorgeCampos I Dont Know is complicated if use the Button. But thanks for your Explanation. :)

    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.