Username/password is incorrect."; } } } // A function to register a new user function register () { if (isset($_REQUEST['username'])) { global $con; // removes backslashes $username = stripslashes($_REQUEST['username']); //escapes special characters in a string $username = mysqli_real_escape_string($con,$username); $email = stripslashes($_REQUEST['email']); $email = mysqli_real_escape_string($con,$email); $password = stripslashes($_REQUEST['password']); $password = mysqli_real_escape_string($con,$password); $query = "INSERT into users (userLogin, userPass, userEmail) VALUES ('$username', '$password', '$email')"; $result = mysqli_query($con,$query); // checks if the username or email addresse is already taken if ($result) { echo "

You are registered successfully.


Click here to Login
"; } elseif (mysqli_errno($con) == 1062) { echo "

Username or Email already taken.

"; } } } //A function to read out the userId of the current user function get_userid ($con) { global $con; session_start(); $username = $_SESSION['username']; $sql = "select userId from users where userLogin = '$username'"; $userId = mysqli_query($con, $sql) or die(mysqli_error($con)); $row = $userId->fetch_object(); return $row->userId; } // A function to post a demand function pbinsert ($con) { if (isset($_POST['submit'])) { global $con; $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, userId) VALUES ('$piecesMax', '$piecesMin', '$text', '$date', '$userId')"; $result = mysqli_query($con, $sql) or die(mysqli_error($con)); } } // A function to insert the own posts from the database into the webside function pbget($con) { global $con; $sql = "SELECT * FROM demands"; $result = mysqli_query($con, $sql); while ($row = $result->fetch_assoc()) { echo "

"; echo $row['date'] . "
"; echo $row['text'] ."
" , "
Maximum
"; echo $row['piecesMax'] ."
Minimum
"; echo $row['piecesMin']; echo "

"; } } // A function to edit a demand function editpost($con) { if (isset($_POST['edit'])) { global $con; $demandId = $_POST['demandId']; $piecesMax = $_POST['piecesMax']; $piecesMin = $_POST['piecesMin']; $text = $_POST['text']; // Inserts Updates Database $sql = "UPDATE demands SET piecesMax='$piecesMax', piecesMin='$piecesMin', text='$text' WHERE demandId='$demandId'"; $result = mysqli_query($con, $sql) or die(mysqli_error($con)); header("Location: board.php"); } } // A function to delete a post function deletepost($con) { if (isset($_POST['deletepost'])) { global $con; $demandId = $_POST['demandId']; // Delete Post from Database $sql = "DELETE FROM demands WHERE demandId='$demandId'"; $result = mysqli_query($con, $sql) or die(mysqli_error($con)); header('Location: board.php'); } } ?>