eventmanager/join.php

78 lines
2.7 KiB
PHP
Raw Normal View History

2021-03-27 17:15:10 +01:00
<?php
session_start();
if (!isset($_SESSION['zalogowany']))
{
header('Location: index.php');
exit();
}
ini_set("display_errors", 0);
require_once "dbconnect.php";
$polaczenie = mysqli_connect($host, $db_user, $db_password);
mysqli_query($polaczenie, "SET CHARSET utf8");
mysqli_query($polaczenie, "SET NAMES 'utf8' COLLATE 'utf8_polish_ci'");
mysqli_select_db($polaczenie, $db_name);
$zapytanietxt = "SELECT manager.employeeID, events.id_events, events.quantity FROM manager, events WHERE events.id_events = manager.id_events AND manager.id_events = '".$_SESSION['id_eve']."'";
$rezultat = mysqli_query($polaczenie, $zapytanietxt);
$ile = mysqli_num_rows($rezultat);
$a1 = $_SESSION['e_slots'];
if($ile < $a1){
require_once "dbconnect.php";
$polaczenie = @new mysqli($host, $db_user, $db_password, $db_name);
if ($polaczenie->connect_errno!=0)
{
echo "Error: ".$polaczenie->connect_errno;
}
else
{
#$login = $_SESSION['id_users'];
$login = htmlentities($login, ENT_QUOTES, "UTF-8");
if ($rezultat = @$polaczenie->query(
sprintf("SELECT manager.employeeID, events.id_events FROM manager, events WHERE events.id_events = manager.id_events AND manager.id_events = '".$_SESSION['id_eve']."' AND manager.employeeID='%s'",
mysqli_real_escape_string($polaczenie,$login))))
{
$ilu_userow = $rezultat->num_rows;
if($ilu_userow>0)
{
$wiersz = $rezultat->fetch_assoc();
$_SESSION['id_log'] = "Jesteś już uczestnikiem!";
unset($_SESSION['blad']);
$rezultat->free_result();
header('Location: events.php');
}
else {
ini_set("display_errors", 0);
require_once "dbconnect.php";
$polaczenie = mysqli_connect($host, $db_user, $db_password);
mysqli_query($polaczenie, "SET CHARSET utf8");
mysqli_query($polaczenie, "SET NAMES 'utf8' COLLATE 'utf8_polish_ci'");
mysqli_select_db($polaczenie, $db_name);
$zapytanietxt = "INSERT INTO manager (employeeID,id_events) VALUES ('".$_SESSION['employeeID']."','".$_SESSION['id_eve']."')";
$rezultat = mysqli_query($polaczenie, $zapytanietxt);
#$ile = mysqli_num_rows($rezultat);
header('Location: events.php');
}
}
}
}
else{
$_SESSION['slots_log'] = "Brak miejsc!";
header("Location: events.php");
}
?>