Sada radi, to je to Hvala vam jos jednom
Da li je ovo u redu sto se tice sigurnosti (SQL Injection)?
Usput, izbacio sam mysqli_close($conn); posto mi javlja "PHP Warning: mysqli::close(): Couldn't fetch mysqli in ..." a ostavio sam $conn->close();, posto je ista konekcija u pitanju, i pretpostavljam da warning dobijem jer hocu dva puta da je zatvorim?
<?php
header('Content-Type: text/html; charset=utf-8');
$servername = "localhost";
$username = "projekat";
$password = "...";
$dbname = "...";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$tabela = $_GET['delete_id'];
$query_provera = "SELECT * FROM projekat.Predmeti WHERE SifraPredmeta='$tabela'";
if (isset($tabela) && !empty($tabela))
//$sql = "DELETE FROM projekat.Predmeti WHERE SifraPredmeta='$tabela'";
if ($result = mysqli_query($conn, $query_provera)) {
if ($row = mysqli_fetch_row($result)) {
// postoji
$stmt = $conn->prepare("DELETE FROM projekat.Predmeti WHERE SifraPredmeta = ?");
$stmt->bind_param('s', $tabela);
$stmt->execute();
echo '<script type="text/javascript">
alert("Predmet sa šifrom '.$tabela.' uspešno obrisan!");
window.location = ".../predmeti.php"
</script>';
$stmt->close();
} else {
// ne postoji
echo '<script type="text/javascript">
alert("GREŠKA! Predmet '.$tabela.' ne postoji u bazi. Pokušajte opet...");
window.location = ".../predmeti.php"
</script>';
}
mysqli_free_result($result);
}
//mysqli_close($conn);
$conn->close();
?>
|