The below line generates this error. Can anyone gives me a solution

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\wamp\www\MySite\php files\approve_page.php on line 25

$query = "UPDATE transaction SET approved_status='1' WHERE account_number='$account_number' AND tran_id='$_POST['tran_id']'";

Recommended Answers

Use the following

$query = "UPDATE transaction SET approved_status='1' WHERE account_number='$account_number' AND tran_id='".$_POST['tran_id']."'";

You should consider the use of mysql_real_escape_string() to avoid SQL injection problems.

Jump to Post

It looks like the query is not building correctly. Print your query to identify the problem. Place the following code between line 17 and 18 and post the output here.

echo $query;
Jump to Post

All 8 Replies

Use the following

$query = "UPDATE transaction SET approved_status='1' WHERE account_number='$account_number' AND tran_id='".$_POST['tran_id']."'";

You should consider the use of mysql_real_escape_string() to avoid SQL injection problems.

Thanks it works...

Can you help me in these set of coding. I want to approve records one by one. The below coding works and displays the message "Details have been succesfully approved". But nothing will happen in the transaction table.

The "approved_status" column remains the same . The default value of "o" is there.

<?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";
   }
   
?>

It looks like the query is not building correctly. Print your query to identify the problem. Place the following code between line 17 and 18 and post the output here.

echo $query;

Here is the output.

UPDATE transaction SET approved_status='1' WHERE account_number='' AND tran_id=''Details have been successfully approved

In this MySQL statement, there is no account number and transaction id.

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

Are you providing this information?

At the begining of my coding i defined those parameters

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='';

$_POST is used to get values from a HTML form. Checkout this link on how to use $_POST.

Since i am new to the PHP I didn't get it..

This program works like this.In my main page (cashsup_page.php) there is a link to Approve records. When a user clicks on that it redirects to another page (check_transactions.php) where he has to enter the account number. When he submitted the account number,the relevant details will apppear in another page.(approve_transactions.php). It contains "approve" button which links to the above coding (approve_page.php)

My transaction table looks like this.tran_id is the primary key of the table.

transaction (tran_id, account_number,___)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.