1

Hi I am trying to add my php variable $remove into the query string so that when the submit button is pushed the action that happens is a request made to remove_friend_db.php?user= where user = contained the value of $remove.

while ($row = $result->fetch_row())
{
    echo "<img src='images/$row[0]_thumb.jpg' atl='userThumbnail'>";
    echo "$row[1] $row[2] $row[3]";
    $remove= $row[0];
    ?>
    <form method="GET" action="remove_friend_db.php?remove="<?php "$remove">"">
    <input type="submit" value="Remove Friend">
    </form>
    <?php
}
1
  • $remove is aways blank? Commented Dec 3, 2015 at 18:49

4 Answers 4

3

<?php echo $remove ?>... You're not outputting anything. you're just basically saying "here's a variable" and php's going "ok, whatever".

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

1 Comment

actualy there's a syntax error or two around there, but this is funny :)
3

I am not sure why you are using this technique.
If you want to use Form then make a input field and then send it to the file.

<form method="GET" action="remove_friend_db.php">
    <input type="hidden" name="" id="" value="<?php echo $remove; ?>" />
    <input type="submit" value="Remove Friend">
</form>

2 Comments

But type="text" name=""would show up a text field in the html form.
Make it hidden type="hidden"
2

You should also be able to do it via an hidden input field. Something like this should work ...

while ($row = $result->fetch_row())
{
    echo "<img src='images/$row[0]_thumb.jpg' atl='userThumbnail'>";
    echo "$row[1] $row[2] $row[3]";
    $remove= $row[0];
  ?>
    <form method="GET" action="remove_friend_db.php">
    <input type="hidden" name="remove" value="<?php $remove ?>">
    <input type="submit" value="Remove Friend">
    </form>
  <?php
}

2 Comments

$remove is not inside php tags, it will print as is. $remove
@AlexAndrei yes you're absolutely right. Fixed it in the answer. Thanks for the comment.
0

If you turn on short tags (in php.ini), which are great for templating, you can do the following:

value="<?=$remove?>"

Comments

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.