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:
parent
5f7fd8d0a3
commit
8e061ec901
|
@ -6,12 +6,13 @@ function login ()
|
||||||
{
|
{
|
||||||
session_start();
|
session_start();
|
||||||
if (isset($_REQUEST['username'])) {
|
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 $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);
|
||||||
|
global $current_user;
|
||||||
|
$current_user = $username;
|
||||||
$password = stripslashes($_REQUEST['password']);
|
$password = stripslashes($_REQUEST['password']);
|
||||||
$password = mysqli_real_escape_string($con,$password);
|
$password = mysqli_real_escape_string($con,$password);
|
||||||
$query = "SELECT * FROM users WHERE userLogin='$username'
|
$query = "SELECT * FROM users WHERE userLogin='$username'
|
||||||
|
@ -59,10 +60,12 @@ function register ()
|
||||||
function get_userid ($con)
|
function get_userid ($con)
|
||||||
{
|
{
|
||||||
global $con;
|
global $con;
|
||||||
global $username;
|
session_start();
|
||||||
|
$username = $_SESSION['username'];
|
||||||
$sql = "select userId from users where userLogin = '$username'";
|
$sql = "select userId from users where userLogin = '$username'";
|
||||||
$userId = mysqli_query($con, $sql) or die(mysqli_error($con));
|
$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
|
// A function to post a demand
|
||||||
|
@ -76,9 +79,8 @@ function pbinsert ($con)
|
||||||
$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, userId)
|
||||||
fk_demands_userId)
|
VALUES ('$piecesMax', '$piecesMin', '$text', '$date', '$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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,16 +91,16 @@ function pbget($con)
|
||||||
global $con;
|
global $con;
|
||||||
$sql = "SELECT * FROM demands";
|
$sql = "SELECT * FROM demands";
|
||||||
$result = mysqli_query($con, $sql);
|
$result = mysqli_query($con, $sql);
|
||||||
while($row = $result->fetch_assoc()){
|
while ($row = $result->fetch_assoc()) {
|
||||||
echo "<div class='post-box'><p>";
|
echo "<div class='post-box'><p>";
|
||||||
echo $row['date'] . "<br>";
|
echo $row['date'] . "<br>";
|
||||||
echo $row['text'] ."<br>" , "<br /> Maximum<br/>";
|
echo $row['text'] ."<br>" , "<br /> Maximum<br/>";
|
||||||
echo $row['piecesMax'] ."<br /> Minimum<br/>";
|
echo $row['piecesMax'] ."<br /> Minimum<br/>";
|
||||||
echo $row['piecesMin'];
|
echo $row['piecesMin'];
|
||||||
echo "</p>
|
echo "</p>
|
||||||
<form class= 'delete-form' method= 'POST' action='".deletepost($con)."'>
|
<form class= 'delete-form' method= 'POST' action='".deletepost($con)."'>
|
||||||
<input type='hidden' name='demandId' value='".$row['demandId']."'>
|
<input type='hidden' name='demandId' value='".$row['demandId']."'>
|
||||||
<button type='submit' name= 'deletepost'> Delete</button>
|
<button type='submit' name= 'deletepost'> Delete</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<form class= 'edit-form' method= 'POST' action='editboard.php'>
|
<form class= 'edit-form' method= 'POST' action='editboard.php'>
|
||||||
|
@ -112,7 +114,7 @@ function pbget($con)
|
||||||
</form>
|
</form>
|
||||||
</div>";
|
</div>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// A function to edit a demand
|
// A function to edit a demand
|
||||||
|
|
|
@ -38,7 +38,7 @@ CREATE TABLE if not exists `demands` (
|
||||||
`piecesMax` int(11) DEFAULT NULL,
|
`piecesMax` int(11) DEFAULT NULL,
|
||||||
`date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
`date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
`userId` int(11) NOT NULL,
|
`userId` int(11) NOT NULL,
|
||||||
`tagId` int(11) NOT NULL,
|
`tagId` int(11) NULL,
|
||||||
CONSTRAINT `fk_demands_userId`
|
CONSTRAINT `fk_demands_userId`
|
||||||
FOREIGN KEY (userId) REFERENCES users (userId),
|
FOREIGN KEY (userId) REFERENCES users (userId),
|
||||||
CONSTRAINT `fk_tagId`
|
CONSTRAINT `fk_tagId`
|
||||||
|
|
Loading…
Reference in New Issue