Skip to content

Commit

Permalink
funktioniert
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxim Gofman authored and Maxim Gofman committed Jan 7, 2022
1 parent 521f525 commit e0b7cf4
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 29 deletions.
24 changes: 24 additions & 0 deletions app/getuserdata.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace app;

class getuserdata
{
protected $id;
protected $mysqlConnection;

public function __construct($id, $mysqlConnection)
{
$this->id = $id;
$this->mysqlConnection = $mysqlConnection;
}

public function getData()
{
$command = "SELECT * FROM `userdata` WHERE `userid` LIKE '$this->id';";
$res = mysqli_query($this->mysqlConnection, $command);
return mysqli_fetch_array($res)[1];
}


}
26 changes: 26 additions & 0 deletions app/getuserid.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace app;

class getuserid
{
protected $username;
protected $mysqlConnection;

public function __construct($username, $mysqlConnection)
{
$this->username = $username;
$this->mysqlConnection = $mysqlConnection;
}

public function getID()
{
$command = "SELECT * FROM `useraccounts` WHERE `username` LIKE '$this->username';";
$res = mysqli_query($this->mysqlConnection, $command);
$useraccountsDB = mysqli_fetch_array($res);
return $useraccountsDB[0];

}


}
15 changes: 15 additions & 0 deletions app/register.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,19 @@ public function newUser()
return $this->mysqlconnection->query("INSERT INTO `useraccounts` (`ID`, `username`, `password`, `email`) VALUES (NULL, '$this->name', '$createHashPassword', '$this->email')");
}

public function newUser2()
{
$createHashPassword = password_hash($this->password, PASSWORD_DEFAULT);
return $this->mysqlconnection->query("INSERT INTO `useraccounts` (`ID`, `username`, `password`, `email`) VALUES (NULL, '$this->name', '$createHashPassword', '$this->email');");

$this->getID($this->name, $this->mysqlconnection);


// wir brauchen die ID um ein neues Space zu erstellen
//-> Space erstellen

}

// Beim registieren muss eine neue Space eingerichtet werden!

}
33 changes: 33 additions & 0 deletions app/test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
$entries = $db->query("SELECT `Username` FROM `Accounts` ORDER BY RAND() LIMIT 5;");
$clickTest = "No button has been clicked";
if (isset($_POST["showAllSort"])) {
$entries = $db->query("SELECT `Username` FROM `Accounts` ORDER BY RAND();");
$clickTest = "Show all button has been clicked";

} elseif (isset($_POST["alphabetSort"])) {
$entries = $db->query("SELECT `Username` FROM `Accounts` ORDER BY ASC;");
$clickTest = "Sort by Alphabet has been clicked";
}

echo $clickTest;

while ($row = $entries->fetch_assoc()){
?>

<h3> Other players </h3>
<button name="showAllSort" type="button"> Show All</button>
<button name="alphabetSort" type="button"> Sort by Alphabet</button>
<button name="friendsSort" type="button"> Sort by most friends</button>
<div>
<p>

<div style="padding-bottom: 0.5em">
<p style="display: inline; margin-right: 3em"> <?php echo $row['Username']; ?> </p>
<button name="friends" type="button"> Add Friend </button>
<br>
</div>
<?php
}
?>
</div>
42 changes: 13 additions & 29 deletions src/privateSpace.php
Original file line number Diff line number Diff line change
@@ -1,53 +1,37 @@
<?php
require_once ('../sqlconnect.php');

session_start();

use app\upload;
require_once ('../vendor/autoload.php');
require_once ('../sqlconnect.php');



use app\upload;
use app\getuserid;
use app\getuserdata;

// Check //
if($_SESSION['username'] == NULL){
session_destroy();
header("Location: ../login.php?loggedOut=sessionExpired");
}else{
echo $_SESSION['username']." hat sich erfolreich eingeloggt";

}

if(isset($_POST['submit'])){
session_destroy();
header("Location: ../login.php?loginStatus=logout");
}

$id = (new getuserid($_SESSION['username'], $mysqli))->getID();
echo $id;







$username = $_SESSION['username'];
$query = "SELECT * FROM `useraccounts` WHERE `username` LIKE '$username'";
$result = mysqli_query($mysqli, $query);
$check = mysqli_fetch_array($result);
echo $check[0]; // nun habe ich die id

$id = $check[0];

$new = "SELECT * FROM `userdata` WHERE `userid` LIKE '$id';";
$res = mysqli_query($mysqli, $new);
$update = mysqli_fetch_array($res);
echo "<br>User daten:";
echo $update[1]."<br>";
$oldData = $update[1];
$userdata = (new getuserdata($id, $mysqli))->getData();
echo $userdata;

if(isset($_POST['upload'])){

$newdata = $_POST['text'];
$command = "UPDATE `userdata` SET `data` = '$oldData''$newdata' WHERE `userdata`.`userid` = $id";
return $mysqli->query($command);
// INSERT INTO userdata (userid, data) VALUES ('12', 'sfff');
$command = "UPDATE `userdata` SET `data` = $newdata WHERE `userdata`.`userid` = $id";
$mysqli->query($command);
}


Expand Down

0 comments on commit e0b7cf4

Please sign in to comment.