Jump to content

Editing date


Pradeep_Chinna

Recommended Posts

After clicking edit link(see one.jpg), it is going to edit_form.php(see onepost-164592-0-67732200-1375423564_thumb.jpg.jpg) and taking ID also but NOT displaying anything in my textfields.

PLEASE HELP ME OUT...

 

main code in edit.php:

 

                                       echo ("<td><a href=\"edit_form.php?number=$row[iD]\">Edit</a></td></tr>");

edit_form.php:

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 
 
<html>
 
<head>
 
<title>Form Edit Data</title>
 
</head>
 
<body>
 
<table border="1">
  <tr>
 
    <td align=center>Form Edit Employees Data</td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <table>
 
      <?php
error_reporting(0);
// Connect to the database
$con = mysql_connect("localhost","admin","");
// Make sure we connected succesfully
if(! $con)
{
die('Connection Failed'.mysql_error());
}
 
// Select the database to use
mysql_select_db("test",$con);
 
$order = "SELECT * FROM budget where ID= '$number' ";
 
      $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[iD]" ?>">
 
     
 
        <tr>        
 
          <td>AMOUNT</td>
 
          <td>
 
            <input type="text" name="amount"
 
        size="20" value="<?php echo "$row[AMOUNT]"?>">
 
          </td>
 
        </tr>
 
        <tr>
 
          <td>PUPOSE</td>
 
          <td>
 
            <input type="text" name="purpose" size="40"
 
          value="<?php echo "$row[PURPOSE]"?>">
 
          </td>
 
        </tr>
<tr>
 
          <td>DATE</td>
 
          <td>
 
            <input type="text" name="date" size="40"
 
          value="<?php echo "$row[DATE]"?>">
 
          </td>
 
        </tr>
<tr>        
 
          <td>NAME</td>
 
          <td>
 
            <input type="text" name="name"
 
        size="20" value=" <?php echo "$row[NAME]"?> ">
 
          </td>
 
        </tr>
        
        <tr>
 
          <td align="right">
 
            <input type="submit"
 
          name="submit value" value="Edit">
 
          </td>
 
        </tr>
 
      </form>
 
      </table>
 
   </td>
 
 </tr>
 
</table>
 
</body>
 
</html>
 
Link to comment
Share on other sites

In future, please use the code tags.

 

Try this:

<?PHP

  $con = mysql_connect('127.0.0.1', 'root', '');
 
  if(!$con) {
    die('Connection Failed: '.mysql_error());
  } else {
    mysql_select_db('test', $con);
  }
 
  //### Assign get variable, if it exists
  $rowID = isset($_GET['number']) ? (int)$_GET['number'] : FALSE ;
 
  //### If the number doesn't exist, display error
  if(empty($rowID)) {
    echo 'No row selected to edit.';
    exit;
  }
 
  //### Select row from database table
  $dbQuery  = "SELECT * FROM `budget` WHERE `ID` = {$rowID}";
  $dbResult = mysql_query($dbQuery) or die(mysql_error());
 
  //### Check if a row was returned
  if(!mysql_num_rows($dbResult)) {
    echo 'No row was returned.';
    exit;
  } else {
    $row = mysql_fetch_assoc($dbResult);
  }
 
?>

<form method="post" action="edit_data.php">
  <input type="hidden" name="ID" value="<?PHP echo $row['ID']; ?>">
 
  <table cellspacing="0" cellpadding="0" border="0">
    <tr>        
      <td> AMOUNT </td>
      <td> <input type="text" name="amount" size="20" value="<?PHP echo $row['AMOUNT']; ?>"> </td>
    </tr>
    <tr>
      <td> PUPOSE </td>
      <td> <input type="text" name="purpose" size="40"  value="<?PHP echo $row['PURPOSE']; ?>"> </td>
    </tr>
    <tr>
      <td> DATE </td>
      <td> <input type="text" name="date" size="40" value="<?PHP echo $row['DATE']; ?>"> </td>
    </tr>
    <tr>        
      <td> NAME </td>
      <td> <input type="text" name="name" size="20" value="<?PHP echo $row['NAME']; ?>"> </td>
    </tr>
    <tr>
      <td align="right"> <input type="submit" name="submit value" value="Edit"> </td>
    </tr>
  </table>
 
</form>
Link to comment
Share on other sites

Note that you should validate the number before running the query to prevent SQL injections. If the validation fails, show an error message and avoid running the query. For example, you can make sure you have a number by doing something like the following:

 

 

<?php
$_GET['number'] = trim($_GET['number']);
if(!ctype_digit((string)$_GET['number'])) {
   echo 'Unknown number';
   exit();
}
?>
Link to comment
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.