In the below query,the "Account has been successfully approved" message dispayed. But in the database still approved_status remains '0'.

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


if(isset($_POST['account_number']))
    $account_number=$_POST['account_number'];
else
    $account_number='';
	
$query = "UPDATE account_details SET approved_status='1' WHERE account_number='$account_number'";
$result= mysql_query($query) or die(mysql_error());

   if ($result)
   {
      echo "Account has been successfully approved";
   }
   
  
   
?>

Dani AI

Generated

OP reports the success message but the column still shows 0. That pattern normally means the UPDATE ran without error but affected zero rows (mysql_query returns true on success even when no rows change). Two useful notes from the thread: 's suggestion about adding a trailing semicolon inside the SQL string is unnecessary for API calls (the semicolon is for interactive clients). 's advice to echo the built query and run it in phpMyAdmin is a good debugging step.

A concise troubleshooting checklist:

  • Confirm the form actually posts an account_number value (dump $_POST or log it) and trim whitespace before using it.
  • Verify the script connects to the intended server/database (run SELECT DATABASE() in the same connection).
  • Run the exact echoed UPDATE manually in phpMyAdmin to see whether it matches any row.
  • Check affected-row feedback from PHP (mysqli->affected_rows or mysql_affected_rows) rather than relying on a simple "success" boolean.
  • Look for subtle mismatches (extra spaces, different data type, leading zeros) by selecting LENGTH() or HEX() for the stored account_number.
  • Ensure no triggers or transaction behavior is rolling the change back and that the DB user has UPDATE privileges.

Example of a safer, modern approach (mysqli + prepared statement + affected-row check):

$mysqli = new mysqli('localhost','root','','bank');
if ($mysqli->connect_errno) { die('Connect error: '.$mysqli->connect_error); }

$acc = isset($_POST['account_number']) ? trim($_POST['account_number']) : '';
$stmt = $mysqli->prepare("UPDATE account_details SET approved_status = 1 WHERE account_number = ?");
$stmt->bind_param('s', $acc);
$stmt->execute();

if ($stmt->affected_rows > 0) {
    echo "Account has been successfully approved";
} else {
    echo "No rows updated — verify account_number, whitespace, permissions, and database selection.";
}

$stmt->close();
$mysqli->close();

Final notes: migrate off deprecated mysql_* functions, use prepared statements to avoid injection, and keep debug prints out of production. Echoing the query (as suggested) helps find mismatches; check affected rows to confirm an actual update.

Recommended Answers

All 3 Replies

There is no ; at the end of the sql query to tell MySQL to execute the code. Try this:

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

I have already included it. But it still not working...

echo query before executing (as i did it below), then run page in browser, copy query and run in phpmyadmin, see where query updates account.
I think your account number is not matching.

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


if(isset($_POST['account_number']))
    $account_number=$_POST['account_number'];
else
    $account_number='';
	
$query = "UPDATE account_details SET approved_status='1' WHERE account_number='$account_number'";
echo $query."<br>";
$result= mysql_query($query) or die(mysql_error());

   if ($result)
   {
      echo "Account has been successfully approved";
   }
   
  
   
?>
Be a part of the DaniWeb community

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