Compare commits

...

3 commits

Author SHA1 Message Date
b25e7118a5 a 2023-10-30 14:34:13 +01:00
d7e069dce2 a 2023-10-30 13:50:59 +01:00
9bf38f2e42 a 2023-10-23 13:54:29 +02:00
4 changed files with 204 additions and 1 deletions

View file

@ -0,0 +1,24 @@
<?php
$sql_mgr = "SELECT id, last_name FROM emp";
$wyn_mgr = mysqli_query($id_conn, $sql_mgr);
if (!$wyn_mgr || mysqli_error($id_conn)) {
echo "Błąd w zapytaniu o departamenty: " . $baza . '(' . mysqli_error($id_conn) . ')';
mysqli_close($id_conn);
exit;
}
$ok_mgr = 0;
$mgrs = '';
while ($w_mgr = mysqli_fetch_array($wyn_mgr)) {
if ($w_mgr['id'] == $mid) {
$ok_mgr = 1;
}
$mgrs .= ', <br> -' . $w_mgr['id'] . ", " . $w_mgr['last_name'];
}
if ($ok_mgr == 0) {
echo 'Nie ma menadżera "' . $mid . '", wybierz jeden z poniższych: ';
echo '<br>' . substr($mgrs, 6);
}
?>

View file

@ -0,0 +1,83 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="description" content="Opis zawartości strony">
<title>Skrypt</title>
</head>
<body>
<?php
$naz=$_POST['nazwisko'];
$imi=$_POST['imie'];
$uid=$_POST['userid'];
$tit=$_POST['title'];
$did=$_POST['dept_id'];
$sal=$_POST['salary'];
$sdt=$_POST['start_dt'];
$mid=$_POST['man_id'];
$uwa=$_POST['uwagi'];
echo ' Nazwisko: ' . $naz . '<br>';
echo ' Imię: ' . $imi . '<br>';
echo ' Użytkownik: ' . $uid . '<br>';
echo ' Stanowisko: ' . $tit . '<br>';
echo ' Departament: ' . $did . '<br>';
echo ' Zarobki: ' . $sal . '<br>';
echo ' Data: ' . $sdt . '<br>';
echo ' Manager: ' . $mid . '<br>';
echo ' Uwagi: ' . $uwa . '<br>';
ini_set('display_errors', '0');
mysqli_report(MYSQLI_REPORT_ERROR);
$host = 'localhost';
$user = 'root';
$haslo = '';
$baza = 'baza_testowa';
$id_conn = mysqli_connect($host, $user, $haslo, $baza);
if (mysqli_connect_errno())
{
echo "Błąd połączenia z MySQL z bazą: " . $baza . ' (' . mysqli_connect_error() . ')';
exit;
}
$sql_tit = "SELECT name FROM title;";
$wyn_tit = mysqli_query($id_conn, $sql_tit);
if (mysqli_error($id_conn)) {
echo "Błąd w zapytaniu o stanowiska: " . $baza . '(' . mysqli_error($id_conn) .')';
mysqli_close($id_conn);
exit;
}
$ok_tit = 0;
$titles = '';
while($w_tit=mysqli_fetch_array($wyn_tit)) {
if ($w_tit['name'] == $tit) {
$ok_tit = 1;
}
$titles = $titles . ', <br> -' . $w_tit['name'];
}
if($ok_tit = 0) {
echo 'Nie ma stanowiska "' .$tit . '", wybierz jedno z poniższych: ';
echo '<br>' . substr($titles, 6);
mysqli_close($id_conn);
exit;
}
$sql_ins = "INSERT INTO emp (id, first_name, last_name, userid, title, dept_id,
salary, start_date, manager_id, comments)
VALUES (Null, '$imi','$naz','$uid','$tit','$did',
'$sal', '$sdt','$mid', '$uwa' );
";
if (!mysqli_query($id_conn, $sql_ins))
{
echo 'Błąd zapisu do bazy:' . mysqli_error($id_conn);
mysqli_close($id_conn); # zamyka połączenie z bazą
exit;
}
mysqli_close($id_conn);
?>
</body>
</html>

View file

@ -87,7 +87,7 @@ if (!mysqli_query($id_conn, $sql_ins))
$ok_dept = 0;
$depts = '';
while ($w_dept = mysqli_fetch_array($wyn_dept)) {
if ($w_dept['id'] . $w_dept['deptName'] . $w_dept['regionName'] == $did) {
if ($w_dept['id'] == $did) {
$ok_dept = 1;
}
$depts .= ', <br> -' . $w_dept['id']. ' | ' . $w_dept['deptName']. ' | ' . $w_dept['regionName'];
@ -98,6 +98,30 @@ if (!mysqli_query($id_conn, $sql_ins))
echo '<br>' . substr($depts, 6);
}
$sql_mgr = "SELECT DISTINCT szef.id, szef.last_name FROM emp AS prac LEFT OUTER JOIN emp AS szef ON prac.manager_id = szef.id";
$wyn_mgr = mysqli_query($id_conn, $sql_mgr);
if (!$wyn_mgr || mysqli_error($id_conn)) {
echo "Błąd w zapytaniu o departamenty: " . $baza . '(' . mysqli_error($id_conn) . ')';
mysqli_close($id_conn);
exit;
}
$ok_mgr = 0;
$mgrs = '';
while ($w_mgr = mysqli_fetch_array($wyn_mgr)) {
if ($w_mgr['id'] == $mid) {
$ok_mgr = 1;
}
$mgrs .= ', <br> -' . $w_mgr['id'] . ", " . $w_mgr['last_name'];
}
if ($ok_mgr == 0) {
echo 'Nie ma menadżera "' . $mid . '", wybierz jeden z poniższych: ';
echo '<br>' . substr($mgrs, 6);
}
mysqli_close($id_conn); # zamyka połączenie z bazą
exit;

View file

@ -0,0 +1,72 @@
<!doctype html>
<html lang="pl">
<head>
<meta charset="utf-8">
<title>Formularz</title>
</head>
<body>
<h3>Pracownicy</h3>
<?php
ini_set('display_errors', '0');
$host = 'localhost';
$user = 'root';
$haslo = '';
$baza = 'baza_testowa';
$id_conn = mysqli_connect($host, $user, $haslo, $baza);
if (mysqli_connect_errno())
{
echo "Błąd połączenia z MySQL z bazą: " . $baza . ' (' . mysqli_connect_error() . ')';
exit;
}
$sql_tit = "SELECT name FROM title;";
$wyn_tit = mysqli_query($id_conn, $sql_tit);
if (mysqli_errno($id_conn))
{
echo "Błąd w zapytania o stanowiska: " . $baza . ' (' . mysqli_error($id_conn) . ')';
mysqli_close($id_conn);
exit;
}
?>
<table cellspacing="0" cellpadding="0" border="0" style="width: 26%;" align="Left">
<tbody align="Left">
<form action='ins_prac.php' method='post'>
<tr><td width="160">Nazwisko:</td><td><input type='text' name='nazwisko' ></td></tr>
<tr><td>Imię: </td><td><input type='text' name='imie' ></td></tr>
<tr><td>Użytkownik: </td><td><input type='text' name='userid' ></td></tr>
<tr><td>Stanowisko: </td><td>
<select id="Stanowiska" name="title">
<?php $tit = '';
$w_tit = mysqli_fetch_array($wyn_tit);
$title = $w_tit['name'];
?>
<option value=<?php printf("%s", "'" . $title . "'"); ?> selected><?php printf("%s", $title); ?></option>
<?php
while ($w_tit = mysqli_fetch_array($wyn_tit))
{
$title = $w_tit['name'];
?>
<option value=<?php printf("%s", "'" . $title . "'"); ?>><?php printf("%s", $title); ?></option>
<?php
}
?>
</select>
</td></tr>
<tr><td>Departament:</td><td><input type='text' name='dept_id' ></td></tr>
<tr><td>Zarobki: </td><td><input type='text' name='salary' ></td></tr>
<tr><td>Data: </td><td><input type='text' name='start_dt' ></td></tr>
<tr><td>ID managera:</td><td><input type='text' name='man_id' ></td></tr>
<tr><td>Uwagi: </td><td><input type='text' name='uwagi' ></td></tr>
<tr><td><p><input type='submit' value='Wyślij'></td></tr>
</form>
</tbody>
</table>
</body>
</html>