通过PHP更新数据库

时间:2012-04-21 23:51:08

标签: php sql

我正在尝试制作表单,以便我的网站成员可以编辑已在数据库上创建的指南。

我仍然是php和数据库的新手,但是如果你花点时间看一下我的编码,我会非常感激。

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

,表格是:

<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>

然而,当我通过网站查看指南时,点击编辑(将您带到上面编码的页面)所有论坛区域都是空白的,就像您要添加新指南一样。

edit_guides.pro.php编码为:

$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+:)");

我还没有能够访问此页面,正如我上面所说,Edit_guide页面就像是在添加新的指南一样。

任何人都可以看到它为什么会这样做的问题? 我哪里错了?

已更改

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

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

现在编辑指南,在表单中显示R.你有

制造者:R

姓名:R

内容:R

0 个答案:

没有答案