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
https://forums.phpfreaks.com/topic/280743-editing-date/
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
https://forums.phpfreaks.com/topic/280743-editing-date/#findComment-1443123
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
https://forums.phpfreaks.com/topic/280743-editing-date/#findComment-1443132
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.