dongwu9647 2015-12-13 16:58
浏览 36
已采纳

PHP中没有在SQL数据库中更新数据

Well I am new to coding,What I am trying is to update data in database through Php .I am trying hard to update data but i don't know where is problem coming ,there is no error too.My first file is

"ppp.html"

<html>
<form action="l.php"method="post">

<input type ="text" name ="complaint">

</input>
<input type="submit"></input>

</html>

Now my "L.php " It also don't show any error .It goes through easily

<?php
        $complaint="";
        if(    
       isset($_POST['complaint']))
       {$complaint =$_POST['complaint'];}

mysql_connect("localhost","root","") or die ("couldnt attack ");
mysql_select_db("site")or die('i surrender');
$query=("SELECT * FROM site2 where category='$complaint'") or die("couldnt select");
$result=mysql_query($query) or die ('hghyt');
while ($complaint= mysql_fetch_array($result))
{



              echo"<td>".'<br>'.$complaint['category']."</tr>";
              ECHO"<TR>"."<A HREF='update.php'>"."UPDATE"."</A>";


             echo "<br/>";
             ECHO"</table>";


    }        
    ?>

Sorry for very wrong query and very inappropriate way of coding but I am learning it all by myself through internet Now my "update.php file"

<html>
<form action="update1.php" method="post">
<input type= "text" name="blue"></input>
<input type= "submit"></input>
</form>
</html>

It also goes of in easy way,and don't show any problem ,now my last file "update1.php"

<?php
$complaint="";
 if(isset ($_POST['complaint']))
 {$complaint =$_POST['complaint'];}

$blue="";
 if(isset ($_POST['blue']))
 {$blue =$_POST['blue'];}
mysql_connect("localhost","root","") or die ("couldnyt coibnovdbs");
mysql_select_db("site") or die ("no databse");
$query=("update site2 set category='$blue' where category ='$complaint'") or die ("couldnt attack");
$result=mysql_query($query) or die("kjkk");
?>

Please help me .It is bothering me,I cant find any solution for it.I think problem is in last file only but it is not showing any errors.

Thank you

  • 写回答

1条回答 默认 最新

  • duanli9001 2015-12-13 17:11
    关注

    Considering the flow of your website, update1.php never receives the value in $complaint, hence fails to update. You need to pass the value to it.

    For example, the following edits should suffice.

    Edit L.php

    echo"<td>".'<br>'.$complaint['category']."</tr>";
    ECHO"<TR>"."<A HREF='update.php?complaint=".$complaint['category']."'>"."UPDATE"."</A>";
    

    Edit update.php

    <html>
    <form action="update1.php" method="post">
    <input type="hidden" name="complaint" value="<?php echo $_GET['complaint'] ?>"
    <input type= "text" name="blue"></input>
    <input type= "submit"></input>
    </form>
    </html>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛