add a function to get the userId from the database
This commit is contained in:
parent
9b0e10ba5c
commit
5f7fd8d0a3
|
@ -8,6 +8,7 @@ function login ()
|
||||||
if (isset($_REQUEST['username'])) {
|
if (isset($_REQUEST['username'])) {
|
||||||
//Checking is user existing in the database or not
|
//Checking is user existing in the database or not
|
||||||
global $con;
|
global $con;
|
||||||
|
global $username;
|
||||||
$username = stripslashes($_REQUEST['username']);
|
$username = stripslashes($_REQUEST['username']);
|
||||||
//escapes special characters in a string
|
//escapes special characters in a string
|
||||||
$username = mysqli_real_escape_string($con,$username);
|
$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
|
// A function to post a demand
|
||||||
function pbinsert ($con)
|
function pbinsert ($con)
|
||||||
{
|
{
|
||||||
if (isset($_POST['submit'])) {
|
if (isset($_POST['submit'])) {
|
||||||
global $con;
|
global $con;
|
||||||
//$userId = $_POST['userId'];
|
$userId = get_userid($con);
|
||||||
$piecesMax = $_POST['piecesMax'];
|
$piecesMax = $_POST['piecesMax'];
|
||||||
$piecesMin = $_POST['piecesMin'];
|
$piecesMin = $_POST['piecesMin'];
|
||||||
$date = $_POST['date'];
|
$date = $_POST['date'];
|
||||||
$text = $_POST['text'];
|
$text = $_POST['text'];
|
||||||
|
|
||||||
// Inserts Data into Database
|
// Inserts Data into Database
|
||||||
$sql = "INSERT INTO demands ( piecesMax, piecesMin, text, date)
|
$sql = "INSERT INTO demands ( piecesMax, piecesMin, text, date,
|
||||||
VALUES ('$piecesMax', '$piecesMin', '$text', '$date')";
|
fk_demands_userId)
|
||||||
|
VALUES ('$piecesMax', '$piecesMin', '$text', '$date', $userId)";
|
||||||
$result = mysqli_query($con, $sql) or die(mysqli_error($con));
|
$result = mysqli_query($con, $sql) or die(mysqli_error($con));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user