我有两个php问件
其中
add.php:
<code><form action="action.php?action=add" method="post"> <table> <tr> <td>姓名</td> <td> <input type="text" name="name"> </td> </tr> <tr> <td>性别</td> <td> <input type="radio" name="sex" value="w">男 <input type="radio" name="sex" value="n">女 </td> </tr> <tr> <td>年龄</td> <td> <input type="text" name="arge"> </td> </tr> <tr> <td>班级</td> <td> <input type="text" name="classId"> </td> </tr> <tr> <td> </td> <td> <input type="submit" value="提交"> <input type="reset" value="重置"> </td> </tr> </table> </form></code>
action.php:
<code>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 "<script>alert('添加成功');window.location='index.php'</script>"; }else{ echo "<script>alert('添加失败');window.history.back();</script>"; } break; }</code>
提交数据时为什么会报如下错误:
<code>Notice: Undefined index: name in /Applications/XAMPP/xamppfiles/htdocs/studentsManager/action.php on line 16 Notice: Undefined index: sex in /Applications/XAMPP/xamppfiles/htdocs/studentsManager/action.php on line 17 Notice: Undefined index: arge in /Applications/XAMPP/xamppfiles/htdocs/studentsManager/action.php on line 18 Notice: Undefined index: classId in /Applications/XAMPP/xamppfiles/htdocs/studentsManager/action.php on line 19 </code>
name sex arge classId 不是都有么 为何还时 未定义??
回复内容:
我有两个php问件
其中
add.php:
<code><form action="action.php?action=add" method="post"> <table> <tr> <td>姓名</td> <td> <input type="text" name="name"> </td> </tr> <tr> <td>性别</td> <td> <input type="radio" name="sex" value="w">男 <input type="radio" name="sex" value="n">女 </td> </tr> <tr> <td>年龄</td> <td> <input type="text" name="arge"> </td> </tr> <tr> <td>班级</td> <td> <input type="text" name="classId"> </td> </tr> <tr> <td> </td> <td> <input type="submit" value="提交"> <input type="reset" value="重置"> </td> </tr> </table> </form></code>
action.php:
<code>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 "<script>alert('添加成功');window.location='index.php'</script>"; }else{ echo "<script>alert('添加失败');window.history.back();</script>"; } break; }</code>
提交数据时为什么会报如下错误:
<code>Notice: Undefined index: name in /Applications/XAMPP/xamppfiles/htdocs/studentsManager/action.php on line 16 Notice: Undefined index: sex in /Applications/XAMPP/xamppfiles/htdocs/studentsManager/action.php on line 17 Notice: Undefined index: arge in /Applications/XAMPP/xamppfiles/htdocs/studentsManager/action.php on line 18 Notice: Undefined index: classId in /Applications/XAMPP/xamppfiles/htdocs/studentsManager/action.php on line 19 </code>
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);

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\ \;||\xc2\xa0)/","其他字符",$str)”语句。

查找方法:1、用strpos(),语法“strpos("字符串值","查找子串")+1”;2、用stripos(),语法“strpos("字符串值","查找子串")+1”。因为字符串是从0开始计数的,因此两个函数获取的位置需要进行加1处理。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

SublimeText3漢化版
中文版,非常好用

Dreamweaver Mac版
視覺化網頁開發工具

EditPlus 中文破解版
體積小,語法高亮,不支援程式碼提示功能

Safe Exam Browser
Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。