html - php 擷取表單資料

來源:互聯網
上載者:User
我有兩個php問件
其中
add.php:

action.php:

switch($_GET['action']){    case "add":        $name = $_POST['name'];        $sex = $_POST['sex'];        $arge = $_POST['arge'];        $classId = $_POST['classId'];        $sql = "insert into students VALUES (NULL ,'{$name}','{$sex}','{$arge}','{$classId}')";        $rw = $pdo->exec($sql);        if($rw>0){            echo "";        }else{            echo "";        }    break;}

提交資料時為什麼會報如下錯誤:

Notice: Undefined index: name in /Applications/XAMPP/xamppfiles/htdocs/studentsManager/action.php on line 16Notice: Undefined index: sex in /Applications/XAMPP/xamppfiles/htdocs/studentsManager/action.php on line 17Notice: Undefined index: arge in /Applications/XAMPP/xamppfiles/htdocs/studentsManager/action.php on line 18Notice: Undefined index: classId in /Applications/XAMPP/xamppfiles/htdocs/studentsManager/action.php on line 19

name sex arge classId 不是都有麼 為何還時 未定義??

回複內容:

我有兩個php問件
其中
add.php:

action.php:

switch($_GET['action']){    case "add":        $name = $_POST['name'];        $sex = $_POST['sex'];        $arge = $_POST['arge'];        $classId = $_POST['classId'];        $sql = "insert into students VALUES (NULL ,'{$name}','{$sex}','{$arge}','{$classId}')";        $rw = $pdo->exec($sql);        if($rw>0){            echo "";        }else{            echo "";        }    break;}

提交資料時為什麼會報如下錯誤:

Notice: Undefined index: name in /Applications/XAMPP/xamppfiles/htdocs/studentsManager/action.php on line 16Notice: Undefined index: sex in /Applications/XAMPP/xamppfiles/htdocs/studentsManager/action.php on line 17Notice: Undefined index: arge in /Applications/XAMPP/xamppfiles/htdocs/studentsManager/action.php on line 18Notice: Undefined index: classId in /Applications/XAMPP/xamppfiles/htdocs/studentsManager/action.php on line 19

name sex arge classId 不是都有麼 為何還時 未定義??

你後面的錯誤是你 單獨 在地址欄中開啟 你的 action.php?action=add的時候顯示的吧?
當你單獨在瀏覽器中直接開啟你的action.php?action=add的時候, 它是以GET的方式請求的, 而且不會有POST的資料過去, 所以你這個時候, 去取$_POST['xxx'] PHP 會有一個 Notice 的提示(在允許顯示的情況下).

正常從你的 add.php 點按鈕(有填寫頁資料的情況下), 是沒有報你說的那個問題的.

  • -問題沒發現,倒是發現第一次看到case可以這樣用的,就不怕出錯嗎?

form 沒有設定encoding 屬性。

encoding='application/x-www-form-urlencoded'

這樣吧。你先var_dump($_POST);

  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.