I’m putting together a small network script to learn how it’s done. I am running into issues with the “add” script, when a user chooses a friend to add. Can anyone tell me what I might be doing wrong here, or point me in the right direction? All I’m trying to do is run a database query that inserts the users as friends when they press a button. Can you do it in this way! Many thanks for any help =)
[php]<?php // This is how a user can add a friend to view their profile
error_reporting (‘E_ALL’);
// Start the session…
session_start();
// Require a connection to the database…
require_once(‘mysqli_connect.php’);
// Store the user id from sessions as a variable…
$id = $_SESSION[‘user_id’];
if (isset($_POST[‘submitted’])) {
// What is the id of the person this user wants to add?
$mem_id = '$_GET['user_id']';
// Insert this friendship into the database until the other user accepts it...
$q = "INSERT INTO friends (friend_id, user_id, status) VALUES ('$mem_id', '$id', '0') LIMIT 1";
$r = @mysqli_query ($dbc, $q);
// Some action needs to take place here where it shows up on the other user's profile...
$q = "SELECT email FROM users WHERE user_id = '$mem_id'";
$r = @mysqli_query ($dbc, $q);
// Here is the member's email to send the confirmation email to the other user...
$email = mysqli_fetch_row ($r);
// Now send the email...
$body = "You have a friend request. To respond to this request, login and check your requests.";
mail ($trimmed['email'], 'Friend Request', $body, 'From: [email protected]');
}
?>
<form enctype="text/plain" action="add.php" method="post">
<input type="submit" name="submit" value="Add a Friend"/>
<input type="hidden" name="submitted" value="TRUE"/>
</form>[/php]