Meine Codes für die Verhinderung von SQL-Injektion funktioniert nicht. Kann mir jemand helfen?
Ich erhalte diese Warnung:
Notice: Undefined variable: mysqli in C: \ xampp \ htdocs \ teknohuk \ fetch_pages.php on line 18
Fatal error: Uncaught Fehler: Aufruf zu einer Member-Funktion prepare() auf Null in C: \ xampp \ htdocs \ teknohuk \ fetch_pages.php: 18 Stack-Trace: # 0 {main} geworfen in C: \ xampp \ htdocs \ teknohuk \ fetch_pages.php in Zeile 18
Danke.
<?php
include("connection.php"); //include config file
//sanitize post value
$item_per_page = 1;
//throw HTTP error if page number is not valid
$page_number = filter_var($_POST["page"], FILTER_SANITIZE_NUMBER_INT, FILTER_FLAG_STRIP_HIGH);
if(!is_numeric($page_number)){
\t header('HTTP/1.1 500 Invalid page number!');
\t exit();
}
//get current starting point of records
$position = (($page_number-1) * $item_per_page);
//line 17
$results = $mysqli->prepare("SELECT id, haberAd, haberOzet, haberTarih, haberFotoURL FROM haber ORDER BY id DESC LIMIT ?, ?");//line 18
//line19
$results->bind_param("issss", $position, $item_per_page);
$results->execute(); //Execute prepared Query
$results->bind_result($id, $haberAd, $haberOzet, $haberTarih, $haberFotoURL); //bind variables to prepared statement
//output results from database
while($results->fetch()){ //fetch values
\t echo "<div class='haber'> \t
\t \t \t \t <div class='haberResim'><img src='img/haberler/" . $haberFotoURL . ".jpg'></div>
\t \t \t \t <div class='haberYazi'><div class='haberBaslik'>" . $haberAd . "</div>" . $haberOzet . "</div>" .
\t \t \t \t "<div class='haberAciklama'><div class='row'><div class='block'></div></div>
<div class='haberTarih'>" . $haberTarih . "</div></div></div>";
}
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
//Connection.php
$vt_sunucu = 'localhost';
$vt_kullanici_adi = 'root';
$vt_kullanici_sifre = '';
$vt_adi = 'gadmin';
$mysqli = mysqli_connect($vt_sunucu, $vt_kullanici_adi, $vt_kullanici_sifre, $vt_adi);
$mysqli->query("SET NAMES utf8");
if (!$mysqli) {
die("Connection failed: " . mysqli_connect_error());
}
?>
Haben Sie diese Abfrage versucht? Funktioniert es? – Swellar
kann die Variable $ mysqli nicht gefunden werden. Hast du diese Variable '$ mysqli' in connection.php? –
Poste deine connection.php. Sind Sie sicher, dass sie evaluiert und ausgeführt werden? – sfratini