当用户在我的数据库中更新、插入或搜索某些内容时,我需要知道此代码是否有效。我还不熟悉 mysqli_real_escape_string。
如果我们谈论用户输入,我需要在这里使用 $_SESSION 吗?
$connmaj = new mysqli();
if ($connmaj->connect_error) {
die("Connection failed: " . $connmaj->connect_error);
}
//select
$titreItem = mysqli_real_escape_string($link,
$_REQUEST['TITRE_ITE']);
$donateurIte = mysqli_real_escape_string($link,
$_REQUEST['DONATEUR_ITE']);
$mntValeurIte = mysqli_real_escape_string($link,
$_REQUEST['MNT_VALEUR_ITE']);
$sqlSelectItem = "select $titreIte, $donateurIte,
$mntValeurIte from TP2_ITEM where EST_ARCHIVEE_ENC != 'Archivé'";
if ($connmaj->query($sqlSelectItem) === TRUE) {
echo "Succes";
} else {
echo "Error: Aucune information retrouvée." .
$connmaj- >error;
}
// insert
$noItem = mysqli_real_escape_string($link, $_REQUEST['NO_ITEM']);
$noEncan = mysqli_real_escape_string($link, $_REQUEST['NO_ENCAN']);
$noItemEncanItem = mysqli_real_escape_string($link, $_REQUEST['NO_ITEM_ENCAN_ITE']);
$titreItem = mysqli_real_escape_string($link, $_REQUEST['TITRE_ITE']);
$cheminPhotoIte = mysqli_real_escape_string($link, $_REQUEST['CHEMIN_PHOTO_ITE']);
$descIte = mysqli_real_escape_string($link, $_REQUEST['DESC_ITE']);
$donateurIte = mysqli_real_escape_string($link, $_REQUEST['DONATEUR_ITE']);
$mntValeurIte = mysqli_real_escape_string($link, $_REQUEST['MNT_VALEUR_ITE']);
$mntPrixDepartIte = mysqli_real_escape_string($link, $_REQUEST['MNT_PRIX_DEPART_ITE']);
$mntIncrementMiniIte = mysqli_real_escape_string($link, $_REQUEST['MNT_INCREMENT_MINI_ITE']);
$mntAchatImmediatIte = mysqli_real_escape_string($link, $_REQUEST['MNT_ACHAT_IMMEDIAT_ITE']);
$estFermeIte = mysqli_real_escape_string($link, $_REQUEST['EST_FERME_ITE']);
$estPayeIte = mysqli_real_escape_string($link, $_REQUEST['EST_PAYE_ITE']);
$sqlInsertItem = "insert into TP2_ITEM values ('$noItem','$noEncan','$noItemEncanItem','$titreIte',
'$cheminPhotoIte','$descIte','$donateurIte','$mntValeurIte',
'$mntPrixDepartIte','$mntIncrementMiniIte','$mntAchatImmedi . atIte,'$estFermeIte','$estPayeIte')";
if ($connmaj->query($sqlInsertItem) === TRUE) {
echo "Insertion réussie";
} else {
echo "Clé primaire dupliquée" . $connmaj->error;
}
我除了返回用户在我的应用程序中输入的内容。