add a function to get the userId from the database

This commit is contained in:
Andreas Zweili 2017-02-17 10:35:25 +01:00
parent 9b0e10ba5c
commit 5f7fd8d0a3
1 changed files with 15 additions and 4 deletions

View File

@ -8,6 +8,7 @@ function login ()
if (isset($_REQUEST['username'])) {
//Checking is user existing in the database or not
global $con;
global $username;
$username = stripslashes($_REQUEST['username']);
//escapes special characters in a string
$username = mysqli_real_escape_string($con,$username);
@ -54,20 +55,30 @@ function register ()
}
}
//A function to read out the userId of the current user
function get_userid ($con)
{
global $con;
global $username;
$sql = "select userId from users where userLogin = '$username'";
$userId = mysqli_query($con, $sql) or die(mysqli_error($con));
return $userId;
}
// A function to post a demand
function pbinsert ($con)
{
if (isset($_POST['submit'])) {
global $con;
//$userId = $_POST['userId'];
$userId = get_userid($con);
$piecesMax = $_POST['piecesMax'];
$piecesMin = $_POST['piecesMin'];
$date = $_POST['date'];
$text = $_POST['text'];
// Inserts Data into Database
$sql = "INSERT INTO demands ( piecesMax, piecesMin, text, date)
VALUES ('$piecesMax', '$piecesMin', '$text', '$date')";
$sql = "INSERT INTO demands ( piecesMax, piecesMin, text, date,
fk_demands_userId)
VALUES ('$piecesMax', '$piecesMin', '$text', '$date', $userId)";
$result = mysqli_query($con, $sql) or die(mysqli_error($con));
}
}