做一个表单编辑界面 求指导
<?php $myconn=mysql_connect("localhost","root",""); mysql_select_db("login_test",$myconn);?><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)) { ?> <tr> <td><input type="text" name="objname" value="<?php echo $row['objname']?>" /></td> <td><input type="text" name="objinfo" value="<?php echo $row['objinfo']?>" /></td> </tr> <?php } ?> </table> </form> <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'"/> <?php print_r($_POST); if(!empty($_POST)){ $objname=$_POST["objname"]; $objinfo=$_POST["objinfo"]; $strSql="update table_test set objname='$objname',objinfo='$objinfo' where objname='$objname' or objinfo='$objinfo'"; $result=mysql_query($strSql,$myconn); echo"修改成功!"; } ?> </body><?php mysql_close($myconn); ?></html>
新人刚学php没多久
以上代码是我脑补的
结果是post没有传入值,点击提交后text里填写的值自动变回修改前的值
求指导!
回复讨论(解决方案)
if(!$myconn){
echo "连接失败".mysql_error();
}
$result=mysql_query($sql,$myconn);
if(!$result){
die(mysql_error());
}
加多些mysql错误判断,这样代码不清楚哪里错了。
if(!$myconn){
echo "连接失败".mysql_error();
}
$result=mysql_query($sql,$myconn);
if(!$result){
die(mysql_error());
}
加多些mysql错误判断,这样代码不清楚哪里错了。
多谢指导 但是问题还是没解决
你的表单里并没有提交按钮,也没有看到用于提交的 js 代码
所以 $_POST 是不可能得到任何数据的
你的表单里并没有提交按钮,也没有看到用于提交的 js 代码
所以 $_POST 是不可能得到任何数据的
提交按钮一定要写在form里才能获得post吗? 长姿势了
你的表单里并没有提交按钮,也没有看到用于提交的 js 代码
所以 $_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="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"]; $strSql="update table_test set objname='$objname',objinfo='$objinfo' where objname='$objname1' or objinfo='$objinfo1'"; $result=mysql_query($strSql,$myconn); if(!$result){ die(mysql_error()); } echo"修改成功!"; /*$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="text" name="objname" value="<?php echo $objname1?>" /></td> <td><input type="text" name="objinfo" value="<?php echo $objinfo1?>" /></td> </tr> <?php }*/ } ?> </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>
修改之后发现编辑以后只修改了表单最后一行的数据
是因为提出数据进行修改时选择的是打印表单的最后一行数据吗?
难道要按照id提出数据进行修改吗?
你的表单里并没有提交按钮,也没有看到用于提交的 js 代码
所以 $_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="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"]; $strSql="update table_test set objname='$objname',objinfo='$objinfo' where objname='$objname1' or objinfo='$objinfo1'"; $result=mysql_query($strSql,$myconn); if(!$result){ die(mysql_error()); } echo"修改成功!"; /*$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="text" name="objname" value="<?php echo $objname1?>" /></td> <td><input type="text" name="objinfo" value="<?php echo $objinfo1?>" /></td> </tr> <?php }*/ } ?> </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>
修改之后发现编辑以后只修改了表单最后一行的数据
是因为提出数据进行修改时选择的是打印表单的最后一行数据吗?
难道要按照id提出数据进行修改吗?
你那个表单
这里只显示最后一条数据啊,每次循环下一次就会把上一次的值给覆盖掉,所以只会修改掉最后一条数据
你的表单里并没有提交按钮,也没有看到用于提交的 js 代码
所以 $_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="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"]; $strSql="update table_test set objname='$objname',objinfo='$objinfo' where objname='$objname1' or objinfo='$objinfo1'"; $result=mysql_query($strSql,$myconn); if(!$result){ die(mysql_error()); } echo"修改成功!"; /*$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="text" name="objname" value="<?php echo $objname1?>" /></td> <td><input type="text" name="objinfo" value="<?php echo $objinfo1?>" /></td> </tr> <?php }*/ } ?> </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>
修改之后发现编辑以后只修改了表单最后一行的数据
是因为提出数据进行修改时选择的是打印表单的最后一行数据吗?
难道要按照id提出数据进行修改吗?
你那个表单
这里只显示最后一条数据啊,每次循环下一次就会把上一次的值给覆盖掉,所以只会修改掉最后一条数据
谢谢!

Outils d'IA chauds

Undresser.AI Undress
Application basée sur l'IA pour créer des photos de nu réalistes

AI Clothes Remover
Outil d'IA en ligne pour supprimer les vêtements des photos.

Undress AI Tool
Images de déshabillage gratuites

Clothoff.io
Dissolvant de vêtements AI

AI Hentai Generator
Générez AI Hentai gratuitement.

Article chaud

Outils chauds

Bloc-notes++7.3.1
Éditeur de code facile à utiliser et gratuit

SublimeText3 version chinoise
Version chinoise, très simple à utiliser

Envoyer Studio 13.0.1
Puissant environnement de développement intégré PHP

Dreamweaver CS6
Outils de développement Web visuel

SublimeText3 version Mac
Logiciel d'édition de code au niveau de Dieu (SublimeText3)

Laravel simplifie la gestion des données de session temporaires à l'aide de ses méthodes de flash intuitives. Ceci est parfait pour afficher de brefs messages, alertes ou notifications dans votre application. Les données ne persistent que pour la demande ultérieure par défaut: $ demande-

L'extension PHP Client URL (CURL) est un outil puissant pour les développeurs, permettant une interaction transparente avec des serveurs distants et des API REST. En tirant parti de Libcurl, une bibliothèque de transfert de fichiers multi-protocol très respectée, PHP Curl facilite Efficient Execu

Alipay Php ...

Laravel fournit une syntaxe de simulation de réponse HTTP concise, simplifiant les tests d'interaction HTTP. Cette approche réduit considérablement la redondance du code tout en rendant votre simulation de test plus intuitive. L'implémentation de base fournit une variété de raccourcis de type de réponse: Utiliser illuminate \ support \ faades \ http; Http :: faux ([[ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

Voulez-vous fournir des solutions instantanées en temps réel aux problèmes les plus pressants de vos clients? Le chat en direct vous permet d'avoir des conversations en temps réel avec les clients et de résoudre leurs problèmes instantanément. Il vous permet de fournir un service plus rapide à votre personnalité

L'article traite de la liaison statique tardive (LSB) dans PHP, introduite dans PHP 5.3, permettant une résolution d'exécution de la méthode statique nécessite un héritage plus flexible. Problème main: LSB vs polymorphisme traditionnel; Applications pratiques de LSB et perfo potentiel

L'article traite des fonctionnalités de sécurité essentielles dans les cadres pour se protéger contre les vulnérabilités, notamment la validation des entrées, l'authentification et les mises à jour régulières.

L'article examine l'ajout de fonctionnalités personnalisées aux cadres, en se concentrant sur la compréhension de l'architecture, l'identification des points d'extension et les meilleures pratiques pour l'intégration et le débogage.
