Jump to content

Help regarding Approve records


heshan

Recommended Posts

Hi all,

 

I want to approve some records. I have created a page which retrieves relevant data. Now i want to add an "Approve" button and displayed a message as "Successfully approved". How can i do that?

 

<?php
if( isset($_POST['account_number']) && !empty($_POST['account_number']) )
{
  $connect=mysql_connect('localhost','root','');
   mysql_select_db('bank',$connect);

  $sql = sprintf("SELECT `tran_id`, `account_number`, `transaction_type`, `transaction_amount`, `transaction_date` FROM `transaction`    WHERE   `account_number`='%s'", mysql_real_escape_string($_POST['account_number']) );

  $result=mysql_query($sql) or die( mysql_error() );

  if( mysql_num_rows($result)==0 )
  {
    echo "<p>No records found.</p>";
  }
  else
  {
    $row=mysql_fetch_assoc($result);  

    echo '<table>';
    echo '<thead><tr><th>' . implode( '</th><th>', array_keys($row) ) . '</th></tr></thead><tbody>';
    do{
      echo '<tr><td>' . implode('</td><td>',$row) . '</td></tr>';
    }while( $row=mysql_fetch_assoc($result) );

    echo '</tbody></table>';
  }
exit();
}
?>

<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
  <div>Enter Account number:
    <input type="text" name="account_number" value="" />
      <input type="submit" value="Submit"/>
  

Link to comment
https://forums.phpfreaks.com/topic/241324-help-regarding-approve-records/
Share on other sites

Print a link with the data id you want to approve, and when clicked that link update database for approved and show a message

 

if (isset($_GET['approve']) && intval($_GET['approve']) > 0)
{
// Do the approving here.
}
echo '<a href="somepage.php?approve_id='. $someId .'"> Approve here </a>';

Thanks a lot.. I have created 2 pages which retrieves search data. When i click on the "Approve" button it goes to a different page and it looks like this.

 

approve_page.php

 

<?php
   
$connect=mysql_connect('localhost','root','');
mysql_select_db('bank',$connect);

$account_number=$_POST['account_number'];

   $query = "select * from transaction WHERE account_number='$account_number'";
   mysql_query($query) or die(mysql_error());
   
   $query = "UPDATE transaction SET approved_status='1'
   WHERE account_number='$account_number'";
   $result = mysql_query($query) or die(mysql_error());

   if ($result)
   {
      echo "Details have been successfully approved";
   }
   
?>   

 

It updates all the data in the database. But i want to update ONLY a single data based on account number. How can i change the coding?

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.