dsjgk330337 2012-05-17 10:10
浏览 71

SQL Query不更新数据

I wrote a simple form from which a user will change his/her name , Facebook Name and image here is the profile.php code with the form

 <!!--edit form--!!>

 <div id="edit">
 <table width="300" border="0"  align="center" cellpadding="0" cellspacing="1"   
 bgcolor="#CCCCCC">
 <tr>
 <td>
 <table width="100%" border="0" cellpadding="1" cellspacing="1"bgcolor="#FFFFFF">
 <tr>
 <form method="POST" action="save_profile.php">
 <td colspan="3"><strong>Username<br><? echo $row['session'];?></strong></td>
 <td colspan="3"><strong>Name</strong><input type="text" name="name" id="name" 
 value="<?      echo $row['name'];?>"/><br></td>
 <td colspan="3"><strong>Facebook</strong><input type="text" name="fb" id="fb" value="<? echo $row['facebook'];?>"/></td>
 <td colspan="3"><strong>Image</strong><input type="text" name="img" id="img" value="<? echo $row['img'];?>"/></td>
 <input type="hidden" name="pros" />
 <input type="submit" value="Save" />
 </form>

and this is the save_profile.php

 <?
 include"sp-includes/sp-config2.php";
 $resultz = mysql_query($slctq);
 while($rowqw = mysql_fetch_array($resultz, MYSQL_ASSOC))
 {
 if($_POST['pros']){
 $name=$_POST['name'];
 $fb=$_POST['fb'];
 $img=$_POST['img'];
 $do =mysql_query("UPDATE profile SET name='$name', facebook='$fb', img='$img' WHERE      id='$rowqw[id]'");
 }
 echo $rowqw['id'];
 }
 ?>

I dont Know where i am wrong..

  • 写回答

3条回答 默认 最新

  • dongzi4030 2012-05-17 10:15
    关注

    First of all, PLEASE SANITIZE YOUR QUERIES. Your query is completely open for exploitation right now and that might entirely be the reason why it fails.

    Write your query like this:

    mysql_query('UPDATE profile SET name="'.mysql_real_escape_string($name).'", facebook="'.mysql_real_escape_string($fb).'", img="'.mysql_real_escape_string($img).'" WHERE      id="'.mysql_real_escape_string($rowqw['id']).'";');
    

    Also, note that the rowqw index should be written as 'id' instead of id.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看