finalize the function to request the user id

I've had to correct an error in the demands table. Tags can be empty.
This commit is contained in:
Andreas Zweili 2017-02-17 13:52:36 +01:00
parent 5f7fd8d0a3
commit 8e061ec901
2 changed files with 17 additions and 15 deletions

View File

@ -6,12 +6,13 @@ function login ()
{
session_start();
if (isset($_REQUEST['username'])) {
//Checking is user existing in the database or not
//Checking if the user exists 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);
global $current_user;
$current_user = $username;
$password = stripslashes($_REQUEST['password']);
$password = mysqli_real_escape_string($con,$password);
$query = "SELECT * FROM users WHERE userLogin='$username'
@ -59,10 +60,12 @@ function register ()
function get_userid ($con)
{
global $con;
global $username;
session_start();
$username = $_SESSION['username'];
$sql = "select userId from users where userLogin = '$username'";
$userId = mysqli_query($con, $sql) or die(mysqli_error($con));
return $userId;
$row = $userId->fetch_object();
return $row->userId;
}
// A function to post a demand
@ -76,9 +79,8 @@ function pbinsert ($con)
$date = $_POST['date'];
$text = $_POST['text'];
// Inserts Data into Database
$sql = "INSERT INTO demands ( piecesMax, piecesMin, text, date,
fk_demands_userId)
VALUES ('$piecesMax', '$piecesMin', '$text', '$date', $userId)";
$sql = "INSERT INTO demands ( piecesMax, piecesMin, text, date, userId)
VALUES ('$piecesMax', '$piecesMin', '$text', '$date', '$userId')";
$result = mysqli_query($con, $sql) or die(mysqli_error($con));
}
}

View File

@ -38,7 +38,7 @@ CREATE TABLE if not exists `demands` (
`piecesMax` int(11) DEFAULT NULL,
`date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`userId` int(11) NOT NULL,
`tagId` int(11) NOT NULL,
`tagId` int(11) NULL,
CONSTRAINT `fk_demands_userId`
FOREIGN KEY (userId) REFERENCES users (userId),
CONSTRAINT `fk_tagId`