Jump to content

Help need in this query


heshan

Recommended Posts

Hi,

 

According to my application first the user has to search details based on account number. Then the relevant details are retrived from the database.Thereafter the user has to approve records based on accuracy.

 

I have this problem in the below coding. Can anyone help me out.... :(

Eventhough the below coding displays the message "Details have been successfully approved" there is nothing happen to my transaction table. The default value of the approved_status is "0". It does not changed to "1".

 

transaction (tran_id, account_number,___,approved_status)

 

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

if(isset($_POST['account_number']))
    $account_number=$_POST['account_number'];
else
    $account_number='';

if(isset($_POST['tran_id']))
    $tran_id=$_POST['tran_id'];
else
    $tran_id='';

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

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

Link to comment
Share on other sites

Change

echo "Details have been successfully approved";

 

to

echo "Details have been successfully approved. -----> {$query}";

 

See what it outputs for the account number and transaction id. Then copy it, go to PHPMyAdmin and run that sql and see what it says.

Link to comment
Share on other sites

@teynon;i did that. The output is like this..

 

UPDATE transaction SET approved_status='1' WHERE account_number='' AND tran_id='' .

I copy it and paste in phpMyadmin. It does not affect any rows..

 

@wildteen; If i use mysql_affected_rows() function it generates following error message.

 

Warning: mysql_affected_rows() expects parameter 1 to be resource, string given in C:\wamp\www\MySite\php files\approve_page.php on line 36

Link to comment
Share on other sites

@wildteen; If i use mysql_affected_rows() function it generates following error message.

 

Warning: mysql_affected_rows() expects parameter 1 to be resource, string given in C:\wamp\www\MySite\php files\approve_page.php on line 36

What variable are you passing mysql_affected_rows? You should be giving it the $result variable not the $query variable.

Link to comment
Share on other sites

UPDATE transaction SET approved_status='1' WHERE account_number='' AND tran_id=''

 

The variables aren't being set. You need to verify your form submission is functioning properly. Also, you shouldn't process the update unless the values are good.

Link to comment
Share on other sites

@teynon ; i understand the problem.I tried several combinations.. But i cannot find a solution. Pls help me out.

 

I briefly explain how this function works in my system. When user logged into his account (cashsup_page.php) a function called "Approval account" is there.

When he clicks it there is a seperate page loaded where he need to enter the account number and press on submit button (check_transactions.php).

Then all the relevant data in that particular record is retrieved from the database as a text box fields.(approve_transactions.php)

Then user clicks on "Approve" button. The above coding is related to this final step.(approve_page.php)

 

transaction (tran_id, account_number, ___, approved_status)

Link to comment
Share on other sites

The query you posted did not have any values for account number or transaction id. That would indicate that either the fields were not POSTed to the script or they were empty. This would imply that there is a problem with the form that POSTed to this script. Take a look at the form in approve_transactions.php, the one with the "Approve" button. You can post the code here (from <FORM ...> to </FORM>).

 

  • The form needs to have its method set to POST and the action set to the script you are talking about here (approve_page.php).
  • There should be two INPUT fields in that form that are either hidden or text (TYPE=).
  • These fields should have the names: account_number and tran_id.
  • These fields should have their value attribute set to the correct value (account number and transaction id).
  • Note that if you set the DISABLED attribute, some (most) browsers will NOT POST the field when the form is submitted.
  • You can use READONLY to prevent the user from changing the value and still have it POSTed.

 

Note: There really is NO way to be 100% sure that the user did not change the value when they POST the form. It is possible (and relatively easy) to modify these values even if they are hidden or readonly or disabled. From a security standpoint, it is much safer to pass these values in a session.

Link to comment
Share on other sites

Here is my form. approve_transactions.php

 

<form name="form1" method="post" action="" >

    
			  
  <fieldset>
  <legend class="cap">Transaction details</legend>
  <p class="cap"> </p>
  <table width="75%" border="0" cellspacing="0" cellpadding="5" align="center">
  
  
<?php

$account_number='';
$tran_id='';

if(isset($_POST['account_number']))
    $account_number=$_POST['account_number'];
else
    $account_number='';


$sql = sprintf("SELECT `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>";
  }
$query = "select * from transaction WHERE account_number='$account_number'";
$result = mysql_query($query) or die(mysql_error());
while ($row=mysql_fetch_array($result)){

$account_number=$row['account_number'];
$tran_id=$row['tran_id'];

?>

                                          
				  
                         <tr height="30">
					<td> </td>
					<td class="title02" align="left">Transaction Type</td>
					<td class="attribute1" align="left"><select name="transaction_type" id="select">
                          <option selected="selected"><?php echo $row['transaction_type']; ?></option>
                          <option value="Deposits">Deposits</option>
                          <option value="Withdrawals">Withdrawals</option>  </select></td>
                        </tr>
                                                                                                                                              
			       <tr height="30">
					<td width="10%"> </td>

					<td width="25%" class="title02" align="left">Transaction Amount</td>
					<td width="55%" class="attribute1" align="left"><label>
					<input type="text" name="transaction_amount" class="attribute1" value="<?php echo $row['transaction_amount']; ?>" / >
					</label></td>
                        
                        
                        
					<td width="10%"> </td>
				  </tr>
                      
                      <tr height="30">
					<td width="10%"> </td>

					<td width="25%" class="title02" align="left">Transaction Date</td>
					<td width="55%" class="attribute1" align="left"><label>
					<input type="text" id="demo3" name="transaction_date" class="attribute1" value="<?php echo $row['transaction_date']; ?>"/ >
					<img src="../images/cal.gif" onClick="javascript:NewCssCal('demo3','yyyyMMdd')" style="cursor:pointer"/></label></td>
                        
                                               
					<td width="10%"> </td>
				  </tr>
                       <tr height="30">
                       
                       
<?php

   }
   

?>
		  
                      
  </table>
  
  <p align="center">
    <label><a href="approve_page.php">
    <input type="submit" name="submit" value="Approve" class="attribute1" onClick="return Validate();"/>  
     </a></label>     
      <input type="reset" name="reset" value="Reset" class="attribute1" />
  </p>
  </fieldset>
  

<p>  </p>
</form>

Link to comment
Share on other sites

The Action attribute in your FORM tag is blank. That means it will post to the same script.

 

There are no fields in that form with the account_number or tran_id, so these fields will NOT be POSTed to the script. This is why the query is not updating the database.

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.