[php]<?php
require_once(“config/db.php”);
class searchUser {
private $db_connection = null; // database connection
private $user_name = ""; // user's name
private $session_user_id = ""; // user's name
private $user_id = ""; // user's name
/**
* the function "__construct()" automatically starts whenever an object of this class is created,
* you know, when you do "$login = new Login();"
*/
public function __construct() {
// create/read session
session_start();
$this->db_connection = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
$this->user_name = $this->db_connection->real_escape_string($_POST['user_name']);
// database query, getting all the info of the selected user
$checklogin = $this->db_connection->query("SELECT user_name, user_id FROM users WHERE user_name = '" . $this->user_name . "';");
// if this user exists
if ($checklogin->num_rows == 1) {
echo "This user has been found";
$session_user_id = $_SESSION['user_id'];
$this->user_id = $this->db_connection->query("SELECT user_id FROM users WHERE user_name = '" . $this->user_name . "';");
$query_check_user_id = $this->db_connection->query("SELECT * FROM UserRelation WHERE UserID_FK = '" . $this->session_user_id . "', FriendID_FK ='" . $this->user_id . "' ;");
if ($query_check_user_name->num_rows == 1) {
echo "You are already friends with this user";
} else {
$query_new_relationship_insert = $this->db_connection->query("INSERT INTO UserRelation (UserID_FK, FriendID_FK) VALUES('" . $this->user_id . "', '" . $this->session_user_id . "');");
}
} else {
echo "This user could not be found";
}
}
}
?> [/php]
My problem is, when I post something to the form nothing is being output, anyone got any ideas?