I have a problem calling php function when i click submit button:
<?php
if (isset($_GET['username']) === true and empty($_GET['username']) === false) {
$username = $_GET['username'];
if(user_exists($username) === true) {
$profile_user_id = user_id_from_username($username, 'username');
$my_id = $_SESSION['user_id'];
$profile_data = user_data($profile_user_id, 'username', 'first_name', 'last_name', 'email', 'profile');
?>
<h1><?php echo $profile_data['first_name']; ?>'s Profile</h1>
<?php
if($profile_user_id != $my_id) {
$check_friend_query = mysql_query("SELECT id FROM friends WHERE (user_one='$my_id' AND user_two='$profile_user_id') OR (user_one='$profile_user_id' AND user_two='$my_id')");
if(mysql_num_rows($check_friend_query) > 0) {
echo '<a href="">Already Friends </a>- <a href="">Unfriend '. $profile_data['username'] .'</a>';
} else {
$from_query = mysql_query("SELECT id FROM friend_request WHERE `from` = '$profile_user_id' AND `to` = '$my_id'");
$to_query = mysql_query("SELECT id FROM friend_request WHERE `from` = '$my_id' AND `to` = '$profile_user_id'");
if(mysql_num_rows($from_query) == 1) {
echo '<a href="#">Ignore</a> or <a href="">Accept</a>';
} elseif(mysql_num_rows($to_query) == 1){
echo '<a href="#">Cancel Request</a>';
} else {
if(isset($_GET['submit'])) {
friend_request();
header('Location: '.$profile_user_id);
exit();
}
?>
<form action="">
<input type="submit" name="submit" value="Send friend request!">
</form>
<?php
}
}
}
?>
That last else isser($GET['submit'] and function call with form.What is wrong I cant find the solution,it just refreshes the page but doenst send mysql_query. Function that i call is this:
function friend_request() {
if (isset($_GET['username']) === true and empty($_GET['username']) === false) {
$username = $_GET['username'];
if(user_exists($username) === true) {
$profile_user_id = user_id_from_username($username, 'username');
$my_id = $_SESSION['user_id'];
$profile_data = user_data($profile_user_id, 'username', 'first_name', 'last_name', 'email', 'profile');
mysql_query("INSERT INTO friend_request VALUES('', '$my_id', '$profile_user_id')");
}}}
Please help me,im new to php and this annoys me, i've been stuck on this since yesterday evening trying to figure it out.I really dont see whats the problem.How do i change my code?Everything works perfectly expect that friend_request() function part.
in your form username
input is missing, Based on the username
value you have allowed into the block if (isset($_GET['username']) === true and empty($_GET['username']) === false) {
<form action="">
<input type="text" name="username" value="your value">
<input type="submit" name="submit" value="Send friend request!">
</form>