简体   繁体   中英

Edit Member Form Not Updating Database

I'm currently working on a small private website. I'm trying to make it so I can edit a users details in the database. My first page displays all users and details, each user has edit next to their name, then the 2nd page opens a form to input new data for the database. Problem is that it won't update the database. I don't think the form is pulling the information through correctly to the edit page.

Also aware of sql injection issues, but I will sort them after the initial problem is fixed.

TL;DR - Edit member form isn't updating the database. How do I fix it?

This page pulls the members from the dastabase for the admin to select which one he wants to edit. Edit.php:

<html>
<head>
<title>Choose User To Edit</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<table>
  <tr>
    <td align="center">EDIT DATA</td>
  </tr>
  <tr>
    <td>
      <table border="1">
      <?
      include"conn.php";//database connection
      $order = "SELECT * FROM members";
      $result = mysql_query($order);
      while ($row=mysql_fetch_array($result)){
        echo ("<tr><td><a href=\"edit_form.php?id=$row[member_id]\">Edit</a></td>");
        echo ("<td>$row[firstname]</td>");
        echo ("<td>$row[lastname]</td>");
        echo ("<td>$row[member_id]</td>");
        echo ("<td>$row[login]</td>");
        echo ("<td>$row[addline1]</td>");
        echo ("<td>$row[addline2]</td>");
        echo ("<td>$row[town]</td>");
        echo ("<td>$row[county]</td>");
        echo ("<td>$row[postcode]</td>");
        echo ("<td>$row[telenum]</td>");
        echo ("<td>$row[email]</td></tr>");
      }
      ?>
      </table>
    </td>
   </tr>
</table>
</body>
</html>

This one is the form that appears after the admin pressed edit. It should pull through the users data into the text areas to be edited. But it doesn't pull the data through. This is probably where the issues start.

edit-form.php:

<html>
<head>
<title>Edit Client</title>
</head>

<body>
<table border=1>
  <tr>
    <td align=center>Edit The Clients Data</td>
  </tr>
  <tr>
    <td>
      <table>
      <?
      include "conn.php";//database connection
      $order = "SELECT * FROM members 
where member_id='$id'";
      $result = mysql_query($order);
      $row = mysql_fetch_array($result);
      ?>
      <form method="post" action="edit_data.php">
      <input type="hidden" name="id" value="<? echo "$row[member_id]"?>">
         <tr>        
          <td>First Name</td>
          <td>
            <input type="text" name="firstname" 
    size="40" value="<? echo "$row[firstname]"?>">
          </td>
        </tr>
          <td>Last Name</td>
          <td>
            <input type="text" name="lastname" 
    size="40" value="<? echo "$row[lastname]"?>">
          </td>
        </tr>
          <td>Login</td>
          <td>
            <input type="text" name="login" 
    size="40" value="<? echo "$row[login]"?>">
          </td>
          </tr>
          <td>Add Line 1</td>
          <td>
            <input type="text" name="addline1" 
    size="40" value="<? echo "$row[addline1]"?>">
          </td>
        </tr>
          <td>Add Line 2</td>
          <td>
            <input type="text" name="addline2" 
    size="40" value="<? echo "$row[addline2]"?>">
          </td>
        </tr>
          <td>Town</td>
          <td>
            <input type="text" name="town" 
    size="40" value="<? echo "$row[town]"?>">
          </td>
        </tr>
           <td>County</td>
          <td>
            <input type="text" name="county" 
    size="40" value="<? echo "$row[county]"?>">
          </td>
        </tr>
          <td>Postcode</td>
          <td>
            <input type="text" name="postcode" 
    size="40" value="<? echo "$row[postcode]"?>">
          </td>
        </tr>
          <td>telephone number</td>
          <td>
            <input type="text" name="telenum" 
    size="40" value="<? echo "$row[telenum]"?>">
          </td>
        </tr>
        <tr>
          <td>Email</td>
          <td>
            <input type="text" name="email" size="40" 
      value="<? echo "$row[email]"?>">
          </td>
        </tr>
        <tr>
          <td align="right">
             <input type="submit" 
      name="submit value" value="Edit">
          </td>
        </tr>
      </form>
      </table>
     </td>
  </tr>
</table>
</body>
</html>

Finally the exec page that ideally edits the members information using the data entered in the form above. edit-exec.php:

<?
//edit_data.php
include "conn.php";
$id = $_GET["member_id"];
$order = "UPDATE members 
          SET firstname='$_POST[firstname]',
              lastname='$_POST[lastname]',  
              login='$_POST[login]',    
              addline1='$_POST[addline1]',  
              addline2='$_POST[addline2]',  
              town='$_POST[town]',  
              county='$_POST[county]',  
              postcode='$_POST[postcode]',  
              telenum='$_POST[telenum]',  
              email='$_POST[email]' 
          WHERE 
          member_id='$id'";
mysql_query($order);
header("location:edit.php");
?>

So ideally, I would like the edit form to display the information that was selected on the previous page, then update any changes made.

Any help?

Thank you for reading

it looks you using wrrong file in your action form

  <form method="post" action="edit_data.php">
                                  ^^--------wrong file or you didnt show it.

this should be

  <form method="post" action="edit-exec.php">

But its horrible your code , hundred of erros and i cant fix them all for you.

example

value="<? echo "$row[login]"?>" should be value="<?php echo $row['login'] ;?>"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM