Update/Edit from Database via 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

Hello

I am no expert but maybe I can help :slight_smile:

There are a couple of problems I can see. First, where you try to insert the value:
[php]

$guides[coding]
[/php]
This should read:
[php]<?php $guides['coding']; ?>
[/php]
assuming one of the fields in your database is called ‘coding’.
Same with this one:
[php] [/php] should be: [php] [/php] Try that and we'll go from there :)

Sorry!
That should have been
[php]<?php echo $guides['coding']; ?>
[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service