2015-12-13 74 views
0

那么我是新编程的,我所尝试的是通过PHP更新数据库中的数据。我在努力更新数据,但我不知道哪里会出现问题,没有错误too.My第一个文件是PHP中的数据没有在SQL数据库中更新

"ppp.html" 

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

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

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

</html> 

现在我的“L.php” 它也不会通过容易

<?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>"; 


    }   
    ?> 

对不起显示任何错误。它也适用于非常错误的查询和非常不恰当的编码方式,但我通过互联网自己学习这一切 Now我的“update.php文件”

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

它还在简单的方式去的,并没有表现出任何问题,现在我的最后一个文件“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"); 
?> 

请帮助我。它困扰着我,我无法找到它的任何解决方案。我认为问题只在最后一个文件,但它没有显示任何错误。

谢谢

+0

如果查询更改为一个变量,如果你通过phpmyadmin执行查询查,是否正确地更新表? '$ tmpQuery =“update site2 set category ='$ blue'where category ='$ complaint'”; echo $ tmpQuery'; –

+0

如果我通过phpMyAdmin执行查询,它会正确更新.. –

回答

1

考虑您的网站的流量,update1.php从未接收$complaint值,因此无法更新。您需要将值传递给它。

例如,以下编辑就足够了。

编辑L.php

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

编辑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> 
+0

谢谢你很多..它的工作..... –