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
https://forums.phpfreaks.com/topic/139223-solved-putting-a-form-in-php-brackets/
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.

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>

 

?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.