初心者がフォーム編集機能を実装していますが、ボトルネックに遭遇したときに助けが必要です。
<?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は少しは理解できますが、結局のところ、phpとjsの使い方はまだ完全には理解していません。
ディスカッションへの返信(解決策)
ちなみに、このページの前のページには値が渡されていません。
このページのフォーム印刷はすべてデータベースから直接調整されています
投稿するものは最後のレコードのみである必要があります
入力の name 属性は同じ名前です。最後のレコードを取得してください
あなたが投稿するのは最後のレコードだけであるべきです
私はこれを知っています、私の目的を達成するための解決策または特定のコードを見つけたいです
各フォームの名前は異なっている必要があります。そうでない場合は、それしかできません。 get $_POST['objname'] と $_POST['objinfo '] 2 つのポスト値
各フォームの名前は異なっている必要があります。そうでない場合は、2 つのポスト値のみを取得できます $_POST[' objname'] と $_POST['objinfo']
&
に変更します:
row['objid']?>">
< objname1?>" />
;?php echo $objinfo1?>" />
列の名前はすべて同じで、値だけが異なります。別々に
各フォームの名前は異なる必要があります。そうでない場合は、$_POST['objname'] と $_POST ['objinfo'] のみを取得できます。 2 つの post 値は、次のように変更されます。
row[ ' objid'];?>" value="">< objid'];?>" value="" />
試してみます
各フォームの名前は異なる必要があります。そうしないと、$_POST['objname'] と $_POST['objinfo'] の 2 つの投稿値しか取得できません
这么一改怎么用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
<テーブル>
$limit = 5;
$strSql="ニュース制限から*を選択".$limit;
$result=mysql_query($strSql,$myconn);
while($row=mysql_fetch_array($result))
{
$title1=$row['title'];
$link1=$row['link'];
?>
print_r($_POST);
if(!empty($_POST)){
for($i=0;$i<$limit;$i++)
{
$title=$_POST["title"][$i];
$link=$_POST["link"][$i];
$id = $_POST["id"][$i];
$strSql = "UPDATE news SET title='".$title."' , link='".$link."' WHERE id='".$id."'";
$result2=mysql_query($strSql,$myconn);
if(!$result2){
die(mysql_error());
}else{
//echo"修改成功!";
}
}
}
?>
我本地测试了一下,这样是可以用的,以上是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]; 吧。
<テーブル>
$limit = 5;
$strSql="ニュース制限から*を選択".$limit;
$result=mysql_query($strSql,$myconn);
while($row=mysql_fetch_array($result))
{
$title1=$row['title'];
$link1=$row['link'];
?>
print_r($_POST);
if(!empty($_POST)){
for($i=0;$i<$limit;$i++)
{
$title=$_POST["title"][$i];
$link=$_POST["link"][$i];
$id = $_POST["id"][$i];
$strSql = "UPDATE news SET title='".$title."' , link='".$link."' WHERE id='".$id."'";
$result2=mysql_query($strSql,$myconn);
if(!$result2){
die(mysql_error());
}else{
//echo"修改成功!";
}
}
}
?>
我本地测试了一下,这样是可以用的,以上是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的终止值为表单长度,这个我自己来吧
真是太感谢了!
咱不是大佬。。做这行也没多久的。只是在帮助别人的时候自己也能温习。

ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

AI Hentai Generator
AIヘンタイを無料で生成します。

人気の記事

ホットツール

メモ帳++7.3.1
使いやすく無料のコードエディター

SublimeText3 中国語版
中国語版、とても使いやすい

ゼンドスタジオ 13.0.1
強力な PHP 統合開発環境

ドリームウィーバー CS6
ビジュアル Web 開発ツール

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)

ホットトピック









PHPクライアントURL(CURL)拡張機能は、開発者にとって強力なツールであり、リモートサーバーやREST APIとのシームレスな対話を可能にします。尊敬されるマルチプロトコルファイル転送ライブラリであるLibcurlを活用することにより、PHP Curlは効率的なexecuを促進します

顧客の最も差し迫った問題にリアルタイムでインスタントソリューションを提供したいですか? ライブチャットを使用すると、顧客とのリアルタイムな会話を行い、すぐに問題を解決できます。それはあなたがあなたのカスタムにより速いサービスを提供することを可能にします

記事では、PHP 5.3で導入されたPHPの後期静的結合(LSB)について説明し、より柔軟な継承を求める静的メソッドコールのランタイム解像度を可能にします。 LSBの実用的なアプリケーションと潜在的なパフォーマ

JWTは、JSONに基づくオープン標準であり、主にアイデンティティ認証と情報交換のために、当事者間で情報を安全に送信するために使用されます。 1。JWTは、ヘッダー、ペイロード、署名の3つの部分で構成されています。 2。JWTの実用的な原則には、JWTの生成、JWTの検証、ペイロードの解析という3つのステップが含まれます。 3. PHPでの認証にJWTを使用する場合、JWTを生成および検証でき、ユーザーの役割と許可情報を高度な使用に含めることができます。 4.一般的なエラーには、署名検証障害、トークンの有効期限、およびペイロードが大きくなります。デバッグスキルには、デバッグツールの使用とロギングが含まれます。 5.パフォーマンスの最適化とベストプラクティスには、適切な署名アルゴリズムの使用、有効期間を合理的に設定することが含まれます。

記事では、入力検証、認証、定期的な更新など、脆弱性から保護するためのフレームワークの重要なセキュリティ機能について説明します。

この記事では、フレームワークにカスタム機能を追加し、アーキテクチャの理解、拡張ポイントの識別、統合とデバッグのベストプラクティスに焦点を当てています。

PHP開発でPHPのCurlライブラリを使用してJSONデータを送信すると、外部APIと対話する必要があることがよくあります。一般的な方法の1つは、Curlライブラリを使用して投稿を送信することです。
