$username = 'login'; $password = 'haslo'; try { (PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")); $sth->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { } try { $stmt = $sth->prepare('SELECT id_miejsce FROM t_miejsce WHERE id_cm=:cm AND sektor=:sektor AND rzad=:rzad AND miejsce=:miejsce '); $stmt->bindValue(':cm', $cm, PDO::PARAM_INT); $stmt->bindValue(':sektor', $sektor, PDO::PARAM_INT); $stmt->bindValue(':rzad', $rzad, PDO::PARAM_INT); $stmt->bindValue(':miejsce', $miejsce, PDO::PARAM_INT); $stmt->execute(); } catch (PDOException $e) { } if ($stmt->rowCount() == 1) { $row = $stmt->fetch(); $id_miejsce = $row["id_miejsce"]; echo 'Miejsce o takich parametrach już zostało dodane do bazy, jeżeli chcesz do niego przejść nacisnij <a class="koniec" href="index.php?id=wyswietl_miejsce.php&id_miejsce=' . $id_miejsce . '">tutaj</a>'; } else { try { $sth->beginTransaction(); $stmt = $sth->prepare('INSERT INTO t_miejsce SET id_cm=:cm, sektor=:sektor, rzad=:rzad, miejsce=:miejsce, dokument=:dokument, karta=:karta, pojedynczy=:pojedynczy, podwojny=:podwojny, info_d_m=:info_d_m ,data_p_m=NOW()'); $stmt->bindValue(':cm', $cm, PDO::PARAM_INT); $stmt->bindValue(':sektor', $sektor, PDO::PARAM_INT); $stmt->bindValue(':rzad', $rzad, PDO::PARAM_INT); $stmt->bindValue(':miejsce', $miejsce, PDO::PARAM_INT); $stmt->bindValue(':dokument', $dokument, PDO::PARAM_STR); $stmt->bindValue(':karta', $karta, PDO::PARAM_STR); $stmt->bindValue(':pojedynczy', $pojedynczy, PDO::PARAM_INT); $stmt->bindValue(':podwojny', $podwojny, PDO::PARAM_INT); $stmt->bindValue(':info_d_m', $info_d_m, PDO::PARAM_STR); $stmt->execute(); $dodane_miejsce = $sth->lastInsertId(); $stmt = $sth->prepare('INSERT INTO t_dane SET imie=:imie, nazwisko=:nazwisko, data_ur=:data_ur , info=:info, id_miejsce=:id_miejsce, data_p_zm=NOW()'); $stmt->bindValue(':imie', $imie, PDO::PARAM_STR); $stmt->bindValue(':nazwisko', $nazwisko, PDO::PARAM_STR); $stmt->bindValue(':data_ur', $data_ur, PDO::PARAM_STR); $stmt->bindValue(':info', $info, PDO::PARAM_STR); $stmt->bindValue(':id_miejsce', $dodane_miejsce, PDO::PARAM_INT); $stmt->execute(); $dodany_zmarly = $sth->lastInsertId(); $stmt = $sth->prepare('INSERT INTO t_dane_dysponenta SET imie_dys=:imie_dys, nazwisko_dys=:nazwisko_dys, adres=:adres, info_d=:info_d, data_p_d=NOW()'); $stmt->bindValue(':imie_dys', $imie_dys, PDO::PARAM_STR); $stmt->bindValue(':nazwisko_dys', $nazwisko_dys, PDO::PARAM_STR); $stmt->bindValue(':adres', $adres, PDO::PARAM_STR); $stmt->bindValue(':info_d', $info_d, PDO::PARAM_STR); $stmt->execute(); $dodany_dys = $sth->lastInsertId(); $stmt = $sth->prepare('INSERT INTO t_odnowienie SET data_odn=:data_odn, info_o=:info_o, data_p_o=NOW()'); $stmt->bindValue(':data_odn', $data_odn, PDO::PARAM_STR); $stmt->bindValue(':info_o', $info_o, PDO::PARAM_STR); $stmt->execute(); $dodane_odn = $sth->lastInsertId(); $stmt = $sth->prepare('INSERT INTO t_k_odnowienie SET id_dysponenta=:id_dysponenta, id_odnowienie=:id_odnowienie , id_miejsce=:id_miejsce, data_p_odn=NOW()'); $stmt->bindValue(':id_dysponenta', $dodany_dys, PDO::PARAM_INT); $stmt->bindValue(':id_odnowienie', $dodane_odn, PDO::PARAM_INT); $stmt->bindValue(':id_miejsce', $dodane_miejsce, PDO::PARAM_INT); $stmt->execute(); $sth->commit(); } catch (PDOException $e) { $sth->rollBack(); } } $stmt->closeCursor();
zmienne które podpinam pod zapytaniem sprawdzam w innym pliku czy teraz powininiem wywalic z tego sprawdzania addslashes() ? Czy z powyższym kodem da się jeszcze coś zrobić żeby usprawnić jego działanie?