我正在尋求您的幫助以解決兩個我無法解決的問題。第一個并不是真正的問題,而是相當煩人:?phpsession_start(); $_SESSION['pseudo']; $CAT="";//tentative de connexion à la base de donnée try{ $bdd = new PDO('mysql:host=localhost;dbname=espace_membre;charset=utf8', 'root', '');}catch (Exception $e){ die('Erreur : ' . $e->getMessage()); //message d'erreur au cas où la connexion échoue}if(isset($_SESSION['id'])){ //echo "ok"; }else{ //echo "lol"; header('location:connexion.php');} if(isset($_GET['id']) AND $_GET['id'] > 0){ $getid=intval($_GET['id']); $requser= $bdd -> prepare('SELECT * FROM membres WHERE id= ?'); $requser->execute(array($getid)); $userinfo=$requser->fetch();}function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; }$CAT = test_input($_POST["categorie"]);$TYPE= test_input($_POST["typeannonce"]);$WILA= test_input($_POST["wilaya"]);$fk_membres_id=$_SESSION['id']; if(isset($_POST['revenirprofil'])) { header("Location: profil.php?id=".$_SESSION['id']); }if(isset($_POST['article_titre']) AND isset($_POST['article_description']) AND isset($_POST['categorie']) AND isset($_POST['wilaya']) AND isset($_POST['typeannonce']) )好吧,該頁面顯示了三個錯誤:注意:未定義索引:第 44 行 C:\wamp\www\projet3\formulaireajout.php 中的 categorie 注意:未定義索引:第 45 行 C:\wamp\www\projet3\formulaireajout.php 中的 typeannonce 注意:未定義索引:wilaya在 C:\wamp\www\projet3\formulaireajout.php 第 46 行但令人驚訝的是,代碼仍然有效,并且在完成并將表單發送到數據庫后,這 3 個通知消失了。除了神秘的 3 個錯誤(這些錯誤并不是真正的錯誤)之外,一切都運行良好我的第二個問題可能看起來像是 SQL 查詢中的輸入錯誤,但仍然無法找到問題所在。
1 回答

楊__羊羊
TA貢獻1943條經驗 獲得超7個贊
這是因為無論您是否提交了表單,您的 php 代碼都會在頁面加載后立即執行。在您尚未提交表單之前,$_POST 全局變量無權訪問 categorie、typeannoance 和 wilaya。
當您提交它時,這些值可以通過$_POST 全局變量訪問,這就是這些通知消失的原因。
嘗試首先使用isset()函數檢查它們的存在,這應該可以解決您的問題
- 1 回答
- 0 關注
- 177 瀏覽
添加回答
舉報
0/150
提交
取消