Jump to content

[SOLVED] putting a form in php brackets


contra10

Recommended Posts

maybe im attempting this the wrong way but i want to put a form in the brackets as im attempting to have an add friend, reject friend. If i put the form seperate then it will only say add friend and reject friend once instead for each person who adds the user

 

my code is

	<?php
mysql_connect("localhost", "root", "") or die(mysql_error()); 
mysql_select_db("registration") or die(mysql_error()); 

$requestint = 1;

$data = ("SELECT * FROM friend_request WHERE requestname = '$username' AND value = '$requestint' ORDER BY frid DESC") or die(mysql_error()); 
$postrequest = mysql_query($data); 

while($info = mysql_fetch_array($postrequest)) 
{ 
$userrequesting= "{$info['username']}";

echo "$userrequesting wants to be your friend <input type='submit' name='add' value='Add Friend'>
<input type='submit' name='reject' value='Reject Friend'></a><br>";
}



?>

	<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table border="0" width="500" align="center" height="100">
<tr>
<td align="right"><input type="submit" name="add" value="Add Friend"></td>
<td align="right"><input type="submit" name="reject" value="Reject Friend"></td></tr>
</table>
</form>

the form in the php brackets or the buttons of the form are the way that i want my request to look like, but i need to do an action and i can't put  $_SERVER['PHP_SELF']; tell me if im making any sense

Link to comment
Share on other sites

1.) You need to place that loop between the <form> tags - otherwise those submit buttons you're echoing wont be part of the form.

2.) You're going to need some way of identifying which friend requests are being accepted/rejected. Perhaps make the submit button's name an array with the id of the friend/friend request as the key.

Link to comment
Share on other sites

something like this

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table border="0" width="500" align="center" height="100">
<tr>
<?php
mysql_connect("localhost", "root", "") or die(mysql_error()); 
mysql_select_db("registration") or die(mysql_error()); 

$requestint = 1;

$data = ("SELECT * FROM friend_request WHERE requestname = '$username' AND value = '$requestint' ORDER BY frid DESC") or die(mysql_error()); 
$postrequest = mysql_query($data); 

while($info = mysql_fetch_array($postrequest)) 
{ 
$userrequesting= "{$info['username']}";

echo "$userrequesting wants to be your friend <input type='submit' name='add' value='Add Friend'>
<input type='submit' name='reject' value='Reject Friend'></a><br>";
}



?>
</table>
</form>

 

?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.