This commit is contained in:
FlyInTheBox 2023-10-23 13:54:29 +02:00
parent 0691e0d7ac
commit 9bf38f2e42
3 changed files with 179 additions and 0 deletions

View file

@ -0,0 +1,24 @@
<?php $sql_dept = "SELECT id FROM dept;";
$wyn_dept = mysqli_query($id_conn, $sql_dept);
if (mysqli_error($id_conn)) {
echo "Błąd w zapytaniu o stanowiska: " . $baza . '(' . mysqli_error($id_conn) .')';
mysqli_close($id_conn);
exit;
}
$ok_dept = 0;
$depts = '';
$dept = '';
while($w_dept=mysqli_fetch_array($wyn_dept)) {
if ($w_dept['id'] == $dept) {
$ok_dept = 1;
}
$depts = $depts . ', <br> -' . $w_dept['id'];
}
if($ok_dept == 0) {
echo 'Nie ma departamentu "' .$dept . '", wybierz jedno z poniższych: ';
echo '<br>' . substr($depts, 6);
mysqli_close($id_conn);
exit;
}

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

@ -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='_MN_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>