<?php $myconn=mysql_connect("localhost","root",""); mysql_select_db("login_test",$myconn); if(!$myconn){ echo "连接失败".mysql_error(); }?><html> <head> <title>Edit</title> <link href="css.css" rel="stylesheet" type="text/css" /> </head> <body> <form method="POST"> <table> <tr class="table_head"> <td>objname</td> <td>objinfo</td> </tr> <?php $strSql="select * from table_test"; $result=mysql_query($strSql,$myconn); while($row=mysql_fetch_array($result)) { $objname1=$row['objname']; $objinfo1=$row['objinfo']; ?> <tr> <td><input type="hidden" name="id" value="<?php echo $row['objid']?>"> <input type="text" name="objname" value="<?php echo $objname1?>" /></td> <td><input type="text" name="objinfo" value="<?php echo $objinfo1?>" /></td> </tr> <?php } print_r($_POST); if(!empty($_POST)){ $objname=$_POST["objname"]; $objinfo=$_POST["objinfo"]; $id = $_POST['id']; $strSql="update table_test set objname='$objname',objinfo='$objinfo' where objid='$id'"; $result=mysql_query($strSql,$myconn); if(!$result){ die(mysql_error()); } echo"修改成功!"; } ?> </table> <br> <div style="display:inline;"> <input type="submit" class="button_black"/> <input type="button" class="button_black" value="返回" onclick="javascript:document.location.href='test.php'"/> </form> </body><?php mysql_close($myconn); ?></html>
以上是代码,只能成功修改最后一行,原因是我用while读取后Post选择的总是最后一行,想了有段时间了想不出怎么做
求指导,最好有代码,js可以看懂一点,Jquery咱不会使,毕竟php和js还没完全搞明白
回复讨论(解决方案)
顺带一提,这个页面的前一个页面没有传任何值出来,没有session。
这个页面表单打印全是直接从数据库调的
没人吗
你post的应该只有最后一个记录
input 的name属性名一样,取最后一个
你post的应该只有最后一个记录
这个我知道了,我想求个解决思路或者具体代码来实现我的目的
你每个表单的name得不同,不然只能获取到$_POST[‘objname’]和$_POST['objinfo']两个post值
你每个表单的name得不同,不然只能获取到$_POST[‘objname’]和$_POST['objinfo']两个post值
" value="" />
input 的name属性名一样,取最后一个
我是用id调的数据,问题在三个column的name都是一样的,只有value不一样,怎么才能把他们分开分别调用
你每个表单的name得不同,不然只能获取到$_POST[‘objname’]和$_POST['objinfo']两个post值
" value="" />
这个思路好!我试试
你每个表单的name得不同,不然只能获取到$_POST[‘objname’]和$_POST['objinfo']两个post值
" value="" />
这么一改怎么用post提数据啊?
$objname=$_POST["objname"];怎么写
你还要能分条保存啊?那分数组。
" />
这样,获得三个数组。之后你想直接插还是整合成一个数组再插都行
你还要能分条保存啊?那分数组。
" />
这样,获得三个数组。之后你想直接插还是整合成一个数组再插都行
<?php $myconn=mysql_connect("localhost","root",""); mysql_select_db("login_test",$myconn); if(!$myconn){ echo "连接失败".mysql_error(); }?><html> <head> <title>Edit</title> <link href="css.css" rel="stylesheet" type="text/css" /> </head> <body> <form method="POST"> <table> <tr class="table_head"> <td>objname</td> <td>objinfo</td> </tr> <?php $strSql="select * from table_test"; $result=mysql_query($strSql,$myconn); while($row=mysql_fetch_array($result)) { $objname1=$row['objname']; $objinfo1=$row['objinfo']; ?> <tr> <td><input type="hidden" name="id[]" value="<?php echo $row['objid']?>"> <input type="text" name="objname[]" value="<?php echo $objname1?>" /></td> <td><input type="text" name="objinfo[]" value="<?php echo $objinfo1?>" /></td> </tr> <?php } print_r($_POST); if(!empty($_POST)){ $i=0; while($row=mysql_fetch_array($result)) { $objname=$_POST["objname[i]"]; $objinfo=$_POST["objinfo[i]"]; $id = $_POST["id[i]"]; $strSql2="update table_test set objname='$objname',objinfo='$objinfo' where objid='$id'"; $result2=mysql_query($strSql,$myconn); if(!$result2){ die(mysql_error()); } $i++; } echo"修改成功!"; } ?> </table> <br> <div style="display:inline;"> <input type="submit" class="button_black"/> <input type="button" class="button_black" value="返回" onclick="javascript:document.location.href='test.php'"/> </form> </body><?php mysql_close($myconn); ?></html>
我按照你的思路改成这样了
post获得的是一整个表单,我让他逐条更新写入,但是为啥数据库那边没改啊
post获得的值打在这里:Array ( [id] => Array ( [0] => 7 [1] => 8 [2] => 9 [3] => 10 ) [objname] => Array ( [0] => 123123 [1] => 321 [2] => 456 [3] => 654 ) [objinfo] => Array ( [0] => 132132 [1] => 321 [2] => 456 [3] => 654 ) )
你还要能分条保存啊?那分数组。
" />
这样,获得三个数组。之后你想直接插还是整合成一个数组再插都行
这个数组思路好,赞一个,这样post取值的通过遍历数组就可以区分不同的name:_POST['objname[0],学习了,我想法是通过js修改name值,有点蛋疼!
你还要能分条保存啊?那分数组。
" />
这样,获得三个数组。之后你想直接插还是整合成一个数组再插都行
<?php $myconn=mysql_connect("localhost","root",""); mysql_select_db("login_test",$myconn); if(!$myconn){ echo "连接失败".mysql_error(); }?><html> <head> <title>Edit</title> <link href="css.css" rel="stylesheet" type="text/css" /> </head> <body> <form method="POST"> <table> <tr class="table_head"> <td>objname</td> <td>objinfo</td> </tr> <?php $strSql="select * from table_test"; $result=mysql_query($strSql,$myconn); while($row=mysql_fetch_array($result)) { $objname1=$row['objname']; $objinfo1=$row['objinfo']; ?> <tr> <td><input type="hidden" name="id[]" value="<?php echo $row['objid']?>"> <input type="text" name="objname[]" value="<?php echo $objname1?>" /></td> <td><input type="text" name="objinfo[]" value="<?php echo $objinfo1?>" /></td> </tr> <?php } print_r($_POST); if(!empty($_POST)){ $i=0; while($row=mysql_fetch_array($result)) { $objname=$_POST["objname[i]"]; $objinfo=$_POST["objinfo[i]"]; $id = $_POST["id[i]"]; $strSql2="update table_test set objname='$objname',objinfo='$objinfo' where objid='$id'"; $result2=mysql_query($strSql,$myconn); if(!$result2){ die(mysql_error()); } $i++; } echo"修改成功!"; } ?> </table> <br> <div style="display:inline;"> <input type="submit" class="button_black"/> <input type="button" class="button_black" value="返回" onclick="javascript:document.location.href='test.php'"/> </form> </body><?php mysql_close($myconn); ?></html>
我按照你的思路改成这样了
post获得的是一整个表单,我让他逐条更新写入,但是为啥数据库那边没改啊
post获得的值打在这里:Array ( [id] => Array ( [0] => 7 [1] => 8 [2] => 9 [3] => 10 ) [objname] => Array ( [0] => 123123 [1] => 321 [2] => 456 [3] => 654 ) [objinfo] => Array ( [0] => 132132 [1] => 321 [2] => 456 [3] => 654 ) )
$_POST["objname[i]"];这个是不是有问题。
你还要能分条保存啊?那分数组。
" />
这样,获得三个数组。之后你想直接插还是整合成一个数组再插都行
<?php $myconn=mysql_connect("localhost","root",""); mysql_select_db("login_test",$myconn); if(!$myconn){ echo "连接失败".mysql_error(); }?><html> <head> <title>Edit</title> <link href="css.css" rel="stylesheet" type="text/css" /> </head> <body> <form method="POST"> <table> <tr class="table_head"> <td>objname</td> <td>objinfo</td> </tr> <?php $strSql="select * from table_test"; $result=mysql_query($strSql,$myconn); while($row=mysql_fetch_array($result)) { $objname1=$row['objname']; $objinfo1=$row['objinfo']; ?> <tr> <td><input type="hidden" name="id[]" value="<?php echo $row['objid']?>"> <input type="text" name="objname[]" value="<?php echo $objname1?>" /></td> <td><input type="text" name="objinfo[]" value="<?php echo $objinfo1?>" /></td> </tr> <?php } print_r($_POST); if(!empty($_POST)){ $i=0; while($row=mysql_fetch_array($result)) { $objname=$_POST["objname[i]"]; $objinfo=$_POST["objinfo[i]"]; $id = $_POST["id[i]"]; $strSql2="update table_test set objname='$objname',objinfo='$objinfo' where objid='$id'"; $result2=mysql_query($strSql,$myconn); if(!$result2){ die(mysql_error()); } $i++; } echo"修改成功!"; } ?> </table> <br> <div style="display:inline;"> <input type="submit" class="button_black"/> <input type="button" class="button_black" value="返回" onclick="javascript:document.location.href='test.php'"/> </form> </body><?php mysql_close($myconn); ?></html>
我按照你的思路改成这样了
post获得的是一整个表单,我让他逐条更新写入,但是为啥数据库那边没改啊
post获得的值打在这里:Array ( [id] => Array ( [0] => 7 [1] => 8 [2] => 9 [3] => 10 ) [objname] => Array ( [0] => 123123 [1] => 321 [2] => 456 [3] => 654 ) [objinfo] => Array ( [0] => 132132 [1] => 321 [2] => 456 [3] => 654 ) )
$_POST["objname[i]"];这个是不是有问题。
改成$i了还是不行,有引号方面的问题吗?
你还要能分条保存啊?那分数组。
" />
这样,获得三个数组。之后你想直接插还是整合成一个数组再插都行
<?php $myconn=mysql_connect("localhost","root",""); mysql_select_db("login_test",$myconn); if(!$myconn){ echo "连接失败".mysql_error(); }?><html> <head> <title>Edit</title> <link href="css.css" rel="stylesheet" type="text/css" /> </head> <body> <form method="POST"> <table> <tr class="table_head"> <td>objname</td> <td>objinfo</td> </tr> <?php $strSql="select * from table_test"; $result=mysql_query($strSql,$myconn); while($row=mysql_fetch_array($result)) { $objname1=$row['objname']; $objinfo1=$row['objinfo']; ?> <tr> <td><input type="hidden" name="id[]" value="<?php echo $row['objid']?>"> <input type="text" name="objname[]" value="<?php echo $objname1?>" /></td> <td><input type="text" name="objinfo[]" value="<?php echo $objinfo1?>" /></td> </tr> <?php } print_r($_POST); if(!empty($_POST)){ $i=0; while($row=mysql_fetch_array($result)) { $objname=$_POST["objname[i]"]; $objinfo=$_POST["objinfo[i]"]; $id = $_POST["id[i]"]; $strSql2="update table_test set objname='$objname',objinfo='$objinfo' where objid='$id'"; $result2=mysql_query($strSql,$myconn); if(!$result2){ die(mysql_error()); } $i++; } echo"修改成功!"; } ?> </table> <br> <div style="display:inline;"> <input type="submit" class="button_black"/> <input type="button" class="button_black" value="返回" onclick="javascript:document.location.href='test.php'"/> </form> </body><?php mysql_close($myconn); ?></html>
我按照你的思路改成这样了
post获得的是一整个表单,我让他逐条更新写入,但是为啥数据库那边没改啊
post获得的值打在这里:Array ( [id] => Array ( [0] => 7 [1] => 8 [2] => 9 [3] => 10 ) [objname] => Array ( [0] => 123123 [1] => 321 [2] => 456 [3] => 654 ) [objinfo] => Array ( [0] => 132132 [1] => 321 [2] => 456 [3] => 654 ) )
$_POST["objname[i]"];这个是不是有问题。
改成$i了还是不行,有引号方面的问题吗?
这样想好像不是很好,现在不是可以获得post过来的3个数组了吗,你根据3个数组再组合下,分别插入数据库,不要想着把$_POST[["objname[i]"]插入数据库,而是把$data=array();$data=$_POST["objname"],然后在分别把3个新定义的数组插入数据库。
if(!empty($_POST)){ while($row=mysql_fetch_array($result)) { $objname=$_POST["objname[]"]; print_r($_POST["objname[]"]); print_r($objname); $objinfo=$_POST["objinfo[]"]; $id = $_POST["id[]"]; $strSql2="update table_test set objname='$objname',objinfo='$objinfo' where objid='$id'"; $result2=mysql_query($strSql,$myconn); if(!$result2){ die(mysql_error()); } } echo"修改成功!"; }
想了一下,是不是不用$i也行,但是还是取不出post里数组的数据(感觉是个基础问题)
有劳大佬了
你还要能分条保存啊?那分数组。
" />
这样,获得三个数组。之后你想直接插还是整合成一个数组再插都行
<?php $myconn=mysql_connect("localhost","root",""); mysql_select_db("login_test",$myconn); if(!$myconn){ echo "连接失败".mysql_error(); }?><html> <head> <title>Edit</title> <link href="css.css" rel="stylesheet" type="text/css" /> </head> <body> <form method="POST"> <table> <tr class="table_head"> <td>objname</td> <td>objinfo</td> </tr> <?php $strSql="select * from table_test"; $result=mysql_query($strSql,$myconn); while($row=mysql_fetch_array($result)) { $objname1=$row['objname']; $objinfo1=$row['objinfo']; ?> <tr> <td><input type="hidden" name="id[]" value="<?php echo $row['objid']?>"> <input type="text" name="objname[]" value="<?php echo $objname1?>" /></td> <td><input type="text" name="objinfo[]" value="<?php echo $objinfo1?>" /></td> </tr> <?php } print_r($_POST); if(!empty($_POST)){ $i=0; while($row=mysql_fetch_array($result)) { $objname=$_POST["objname[i]"]; $objinfo=$_POST["objinfo[i]"]; $id = $_POST["id[i]"]; $strSql2="update table_test set objname='$objname',objinfo='$objinfo' where objid='$id'"; $result2=mysql_query($strSql,$myconn); if(!$result2){ die(mysql_error()); } $i++; } echo"修改成功!"; } ?> </table> <br> <div style="display:inline;"> <input type="submit" class="button_black"/> <input type="button" class="button_black" value="返回" onclick="javascript:document.location.href='test.php'"/> </form> </body><?php mysql_close($myconn); ?></html>
我按照你的思路改成这样了
post获得的是一整个表单,我让他逐条更新写入,但是为啥数据库那边没改啊
post获得的值打在这里:Array ( [id] => Array ( [0] => 7 [1] => 8 [2] => 9 [3] => 10 ) [objname] => Array ( [0] => 123123 [1] => 321 [2] => 456 [3] => 654 ) [objinfo] => Array ( [0] => 132132 [1] => 321 [2] => 456 [3] => 654 ) )
找了半天,你这执行的是$sqlstr,但定义的字符串是$sqlstr2
title | link |
"> " /> | " /> |
我本地测试了一下,这样是可以用的,以上是table里的代码
if(!empty($_POST)){ while($row=mysql_fetch_array($result)) { $objname=$_POST["objname[]"]; print_r($_POST["objname[]"]); print_r($objname); $objinfo=$_POST["objinfo[]"]; $id = $_POST["id[]"]; $strSql2="update table_test set objname='$objname',objinfo='$objinfo' where objid='$id'"; $result2=mysql_query($strSql,$myconn); if(!$result2){ die(mysql_error()); } } echo"修改成功!"; }
想了一下,是不是不用$i也行,但是还是取不出post里数组的数据(感觉是个基础问题)
有劳大佬了
我写了print_r($_POST["$objname"]);和print_r($_POST["$objname[]"]); 都没反应
$objname=array();
$bojname=$_POST['bojname'];
$objinfo=array();
$bojname=$_POST['bojname'];
$id=array();
$id=$_POST['id'];
for ($i=0,i
}
试试这个思路
用 $objname=$_POST["objname"][$i]; 吧。
title | link |
"> " /> | " /> |
我本地测试了一下,这样是可以用的,以上是table里的代码
原来是这样写的,受教了
用 $objname=$_POST["objname"][$i]; 吧。
一下子没想到这个,$_POST["objname"][$i]这样的得到post的值,应该就可以插入了,问题应该可以解决了。
用 $objname=$_POST["objname"][$i]; 吧。
多谢大佬帮助,基本上问题都解决了,还差一个定循环里i的终止值为表单长度,这个我自己来吧
真是太感谢了!
用 $objname=$_POST["objname"][$i]; 吧。
也多些这位仁兄的热心帮助!太感动了
<?php $myconn=mysql_connect("localhost","root",""); mysql_select_db("login_test",$myconn); if(!$myconn){ echo "连接失败".mysql_error(); }?><html> <head> <title>Edit</title> <link href="css.css" rel="stylesheet" type="text/css" /> </head> <body> <form method="POST"> <table> <tr class="table_head"> <td>objname</td> <td>objinfo</td> </tr> <?php $strSql="select * from table_test"; $result=mysql_query($strSql,$myconn); while($row=mysql_fetch_array($result)) { $objname1=$row['objname']; $objinfo1=$row['objinfo']; ?> <tr> <td><input type="hidden" name="id[]" value="<?php echo $row['objid']?>"> <input type="text" name="objname[]" value="<?php echo $objname1?>" /></td> <td><input type="text" name="objinfo[]" value="<?php echo $objinfo1?>" /></td> </tr> <?php } print_r($_POST); if(!empty($_POST)){ for($i=0;$i< mysql_num_rows($result);$i++){ $objname=$_POST["objname"][$i]; print_r($objname); $objinfo=$_POST["objinfo"][$i]; print_r($objinfo); $id = $_POST["id"][$i]; print_r($id); $strSql2="update table_test set objname='$objname',objinfo='$objinfo' where objid='$id'"; $result2=mysql_query($strSql2,$myconn); if(!$result2){ die(mysql_error()); } } echo"修改成功!"; } ?> </table> <br> <div style="display:inline;"> <input type="submit" class="button_black"/> <input type="button" class="button_black" value="返回" onclick="javascript:document.location.href='test.php'"/> </form> </body><?php mysql_close($myconn); ?></html>
这里是最终成型代码
感谢fedcgfedbe和csjazqx的热心帮助!
用 $objname=$_POST["objname"][$i]; 吧。
多谢大佬帮助,基本上问题都解决了,还差一个定循环里i的终止值为表单长度,这个我自己来吧
真是太感谢了!
咱不是大佬。。做这行也没多久的。只是在帮助别人的时候自己也能温习。

PHP用於構建動態網站,其核心功能包括:1.生成動態內容,通過與數據庫對接實時生成網頁;2.處理用戶交互和表單提交,驗證輸入並響應操作;3.管理會話和用戶認證,提供個性化體驗;4.優化性能和遵循最佳實踐,提升網站效率和安全性。

PHP在數據庫操作和服務器端邏輯處理中使用MySQLi和PDO擴展進行數據庫交互,並通過會話管理等功能處理服務器端邏輯。 1)使用MySQLi或PDO連接數據庫,執行SQL查詢。 2)通過會話管理等功能處理HTTP請求和用戶狀態。 3)使用事務確保數據庫操作的原子性。 4)防止SQL注入,使用異常處理和關閉連接來調試。 5)通過索引和緩存優化性能,編寫可讀性高的代碼並進行錯誤處理。

在PHP中使用預處理語句和PDO可以有效防範SQL注入攻擊。 1)使用PDO連接數據庫並設置錯誤模式。 2)通過prepare方法創建預處理語句,使用佔位符和execute方法傳遞數據。 3)處理查詢結果並確保代碼的安全性和性能。

PHP和Python各有優劣,選擇取決於項目需求和個人偏好。 1.PHP適合快速開發和維護大型Web應用。 2.Python在數據科學和機器學習領域佔據主導地位。

PHP在電子商務、內容管理系統和API開發中廣泛應用。 1)電子商務:用於購物車功能和支付處理。 2)內容管理系統:用於動態內容生成和用戶管理。 3)API開發:用於RESTfulAPI開發和API安全性。通過性能優化和最佳實踐,PHP應用的效率和可維護性得以提升。

PHP可以輕鬆創建互動網頁內容。 1)通過嵌入HTML動態生成內容,根據用戶輸入或數據庫數據實時展示。 2)處理表單提交並生成動態輸出,確保使用htmlspecialchars防XSS。 3)結合MySQL創建用戶註冊系統,使用password_hash和預處理語句增強安全性。掌握這些技巧將提升Web開發效率。

PHP和Python各有優勢,選擇依據項目需求。 1.PHP適合web開發,尤其快速開發和維護網站。 2.Python適用於數據科學、機器學習和人工智能,語法簡潔,適合初學者。

PHP仍然具有活力,其在現代編程領域中依然佔據重要地位。 1)PHP的簡單易學和強大社區支持使其在Web開發中廣泛應用;2)其靈活性和穩定性使其在處理Web表單、數據庫操作和文件處理等方面表現出色;3)PHP不斷進化和優化,適用於初學者和經驗豐富的開發者。


熱AI工具

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

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

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

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

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

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

PhpStorm Mac 版本
最新(2018.2.1 )專業的PHP整合開發工具