Jump to content

Recommended Posts

Hi, I'm having problems trying to edit data from a table in my database.

 

This is the error that appears:

 

An error occurred in script 'C:\wamp\www\html\edit_form.php' on line 12:

mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO)

 

This is therefore relating to this piece of code:

 

<table border=1>
	  <tr>
	    <td align=center>Form Edit Employees Data</td>
	  </tr>
	  <tr>
	    <td>
	      <table>
	      <?php
	      $order = "SELECT username FROM users
	where username='$id'";
	      require_once ('./includes/config.inc.php');
	      $result = mysql_query($order);
	      $row = mysql_fetch_array($result);
	      ?>
	      <form method="post" action="edit_data.php">
	      <input type="hidden" name="id" value="<?php echo "$row[username]"?>">
	        <tr>
	          <td>Username</td>
	          <td>
	            <input type="text" name="username"
	        size="20" value="<?php echo "$row[username]"?>">
	          </td>
	        </tr>
	        <tr>
	          <td align="right">
	            <input type="submit"
	          name="submit value" value="Edit">
	          </td>
	        </tr>
	      </form>
	      </table>
	    </td>
	  </tr>
</table>

 

The weird thing is that this bit of the code connects correctly to the database using the same instruction require_once ('./includes/config.inc.php'); and displays all the usernames so there shouldn't be a problem with the config.inc.php file.

 

<?php # Script 13.8 - edit.php

// Include the configuration file for error management and such.
require_once ('./includes/config.inc.php');

// Set the page title and include the HTML header.
$page_title = 'Users';
include ('./includes/header.html');
?>

<table>
  <tr>
    <td align="center">Edit Users</td>
  </tr>
  <tr>
    <td>
      <table border="1">
      <?php
      require_once ('../mysql_connect.php'); // Connect to the database.
      $order = "SELECT username FROM users";
      $result = mysql_query($order);
      while ($row=mysql_fetch_array($result)){
        echo ("<tr><td>$row[username]</td>");
        echo ("<td><a href=\"edit_form.php?id=$row[username]\">Edit</a></td></tr>");
      }
      ?>
      </table>
    </td>
   </tr>
</table>

<?php
include ('./includes/footer.html');
?>

 

This the final apart of the code, just incase it is needed:

 

<?php
//edit_data.php
require_once ('./includes/config.inc.php');
$order = "UPDATE users
          SET username='$username',

          WHERE
          username='$id'";
mysql_query($order);
header("location:edit.php");
?>

 

Please help! Thanks.

Link to comment
https://forums.phpfreaks.com/topic/194484-editing-data-in-db/
Share on other sites

Cheers that worked! Can't believe I missed that, copied and pasted the wrong line.

 

However I have now moved on to another problem  :(

 

This time the text box appears from edit_form.php however the username is not already filled in as the value that can be changed. When I fill in the box with a changed username it takes me back to the edit.php with the list of usernames that haven't been altered.

 

Any ideas why?

Link to comment
https://forums.phpfreaks.com/topic/194484-editing-data-in-db/#findComment-1022959
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.