duangua6912 2012-04-21 23:51
浏览 42

通过PHP更新数据库

I am trying to make a form so my site members can edit guides already made on the database.

I still new to php and database's but if you would take a moment to look at some of my coding i'd be very grateful.

$id = $_GET['id'];
$guides = mysql_fetch_array(mysql_query("SELECT * FROM guides WHERE id = '$id'"));

and the form is:

<center>
<FORM ACTION="edit_guide.pro.phpid=$id" enctype="multipart/form-data" METHOD=POST>
<table width="446" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td colspan="2"><center>Edit a Guide</center></td>
  </tr>
  <tr>
    <td width="79">Made By:</td>
    <td width="367"><input type="text" name="madeby" value="$guides[username]"></td>
  </tr>
  <tr>
    <td>Name of Guide:</td>
    <td><input type="text" name="name" value="$guides[name]"></td>
  </tr>
<tr>
    <td>Filed Under:</td>
    <td><select name=filedunder>
               <option value=guides>Guides
        <option value=dailies>Dailies Guides


       <option value=gg#h>Game Guides # - H


        <option value=ggiq>Game Guides I - Q


        <option value=ggrz>Game Guides R - Z


        <option value=helpfulguides>Helpful Guides


        <option value=newbie>Newbie Guides
</select></td>
  </tr>
   <tr>
    <td valign="top">Content:</td>
    <td><textarea  name="coding" cols="50" rows="35" value="">$guides[coding]</textarea></td>
  </tr>
  <tr>
    <td>Key Word 1</td>
    <td><input type="text" name="key1" value="None"></td>
  </tr>
    <tr>
    <td>Key Word 2</td>
    <td><input type="text" name="key2" value="None"></td>
  </tr>
    <tr>
    <td>Key Word 3</td>
    <td><input type="text" name="key3" value="None"></td>
  </tr>
    <tr>
    <td>Key Word 4</td>
    <td><input type="text" name="key4" value="None"></td>
  </tr>
    <tr>
    <td>Key Word 5</td>
    <td><input type="text" name="key5" value="None"></td>
  </tr>
    <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td colspan="2"><center><font size="-1"><i>
      <input type=submit name=Submit value="Edit">
    </i></font></center></td>
  </tr>
</table></FORM>
<p>&nbsp;</p></center>

How ever, When I view the guide via site, click on edit (which brings you to the page with above coding) all the forum area's are blank and acts as if you are adding a new guide.

The edit_guides.pro.php coding is:

$id=$_GET['id'];
$madeby = $_POST['madeby'];
$name = $_POST['name'];
$coding = $_POST['coding'];
$key1 = $_POST['key1'];
$key2 = $_POST['key2'];
$key3 = $_POST['key3'];
$key4 = $_POST['key4'];
$key5 = $_POST['key5'];
$filedunder = 'guides';
$filedunder2 = $_POST['filedunder'];



if ((!$madeby) OR (!$name) OR (!$coding) OR (!$filedunder2) OR (!$key1) OR (!$key2) OR (!$key3) OR (!$key4) OR (!$key5))

{

               die(header("Location: $baseurl/staff/edit_guides.php?id=$id&error=Please+do+not+leave+any+info+blank."));

}

else

{
mysql_query("UPDATE guides SET header = '$madeby' WHERE id = '$id'");
mysql_query("UPDATE guides SET header = '$name' WHERE id = '$id'");
mysql_query("UPDATE guides SET subheader = '$filedunder2' WHERE id = '$id'");
mysql_query("UPDATE guides SET news = '$coding' WHERE id = '$id'");
mysql_query("UPDATE guides SET header = '$key1' WHERE id = '$id'");
mysql_query("UPDATE guides SET header = '$key2' WHERE id = '$id'");
mysql_query("UPDATE guides SET header = '$key3' WHERE id = '$id'");
mysql_query("UPDATE guides SET header = '$key4' WHERE id = '$id'");
mysql_query("UPDATE guides SET header = '$key5' WHERE id = '$id'");
    header("Location: $baseurl/staff/index1.php?error=The+news+has+been+updated+:)");

I have not been able to get to this page yet, as I said above, the Edit_guide page is acting as if you are adding new Guides.

Can anyone see the issue to why it is doing this? Where am I going wrong?

Changed

 $guides = mysql_fetch_array(mysql_query("SELECT * FROM guides WHERE id = '$id'"));

to

$guides = mysql_escape_string(mysql_query("SELECT * FROM guides WHERE id = '$id'"));

Now Edit guides, Is Showing R in the Form. So you have

Made By: R

Name: R

Content: R

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测