This commit is contained in:
Logan McInnis
2019-12-04 20:56:23 -05:00
parent 4e1ecb506f
commit 05bc90753f

View File

@@ -23,9 +23,10 @@
$sql_from = "FROM contacts";
$sql_where = "WHERE username = '".$_POST['friend']."'";
$sql_statement = $sql_select." ".$sql_from." ".$sql_where."";
$result2 = $db_connection->query($sql_statement);
$result = $result2->fetchAll();
if(mysqli_num_rows($result) == 0)
$num = 0;
foreach($db_connection->query($sql_statement) as $row)
$num = 1;
if($num == 0)
echo "username doesn't exist";
else
{
@@ -33,9 +34,10 @@
$sql_from = "FROM friendList";
$sql_where = "WHERE username = '".$_SESSION["loggedInUser"]."' and friend = '".$_POST['friend']."'";
$sql_statement = $sql_select." ".$sql_from." ".$sql_where."";
$result2 = $db_connection->query($sql_statement);
$result = $result2->fetchAll();
if(mysqli_num_rows($result) == 1)
$num = 0;
foreach($db_connection->query($sql_statement) as $row)
$num = 1;
if($num == 1)
echo "you already sent a request";
else
{
@@ -43,18 +45,19 @@
$sql_from = "FROM friendList";
$sql_where = "WHERE username = '".$_POST['friend']."' and friend = '".$_SESSION["loggedInUser"]."'";
$sql_statement = $sql_select." ".$sql_from." ".$sql_where."";
$result2 = $db_connection->query($sql_statement);
$result = $result2->fetchAll();
if(mysqli_num_rows($result) == 1)
$num = 0;
foreach($db_connection->query($sql_statement) as $row)
$num = 1;
if($num == 1)
{
$sql_statement = "UPDATE friendList SET confirm = 'true' WHERE username = '".$_POST['friend']."' and friend = '".$_SESSION["loggedInUser"]."'";
$sql_statement = "UPDATE friendList SET confirm = true WHERE username = '".$_POST['friend']."' and friend = '".$_SESSION["loggedInUser"]."'";
$db_connection->query($sql_statement);
$sql_statement = "INSERT INTO friendList VALUES ('".$_SESSION["loggedInUser"]."', '".$_POST['friend']."', 'true')";
$sql_statement = "INSERT INTO friendList VALUES ('".$_SESSION["loggedInUser"]."', '".$_POST['friend']."', true)";
$db_connection->query($sql_statement);
}
else
{
$sql_statement = "INSERT INTO friendList VALUES ('".$_SESSION["loggedInUser"]."', '".$_POST['friend']."', 'false')";
$sql_statement = "INSERT INTO friendList VALUES ('".$_SESSION["loggedInUser"]."', '".$_POST['friend']."', false)";
$db_connection->query($sql_statement);
}
}