Hello,

I have a problem with update in MySql database.

In a university system a student apply for what is called a petition then the admin signs it and adds a note.

When the admin signs for the first time and enters his note it works.

But when the student Apply another time for the same petition and when the admin tries to enter his not and sign.

The note is not inserted to the table.

Notice that the query updates the record in the database and that the two times he insert have different ids.

The weird thing is that the query updates all other fields correctly.
Only the admin note is not updated.


Thing I tried:

I printed it out it worked.

I changed the structure from varchar to text .

I changed the Collation from latin1_swedish_ci to utf8_unicode_ci.

Dani AI

Generated

A short post‑mortem and a practical fix that applies to the symptoms shown in the thread.

The root cause in cases like this is almost always an indexing mismatch: the form used an indexed field group (an array of notes), so the submitted data lives under a single key (for example $_POST['Note']) as an array. Accessing a top‑level numeric key (or the wrong variable) will return nothing or an array rather than the expected string, so every other scalar field updates but the note column ends up empty. ’s print_r suggestion and ’s advice to prefer $_POST were on target for diagnosing that.

Practical checklist and safer code pattern

  • Confirm what the form actually sent with print_r($_POST) and verify that the note appears at $_POST['Note'][$level].
  • Extract, validate and trim the value into a variable before building SQL.
  • Use a prepared statement (bound parameters) instead of concatenating user data into SQL to avoid quoting bugs and injection.
  • Ensure the DB connection uses the correct charset and that the column length is sufficient.
  • Check the update’s affected row count to confirm the WHERE clause matched the intended record.

Example (illustrative) pattern:

$note = isset($_POST['Note'][$level]) ? trim($_POST['Note'][$level]) : '';
$stmt = $pdo->prepare("UPDATE flowdetailsdata SET adminNote = :note WHERE flowDetailsID = :flow AND formDataID = :form");
$stmt->execute([':note'=>$note, ':flow'=>$flowId, ':form'=>$formId]);

Operational tips: enable PDO exceptions (ATTR_ERRMODE => ERRMODE_EXCEPTION), log var_dump/print_r output during testing, and verify form controls aren’t disabled or outside the form. The combination of correct array indexing, prepared statements, and explicit error reporting resolves this class of problems; later noted fixing an inherited bug along these lines.

Recommended Answers

All 13 Replies

Post your query and your table structure.

It seems to be a problem with your query. But can't say anything for sure unless we see your query/code.

Table structure :

flowDetailsDataID int(11)
flowDetailsID int(11)
formDataID int(11)
status enum('Not Yet','Approved','Rejected')
adminNote varchar(30) utf8_unicode_ci
adminApp varchar(30) latin1_swedish_ci
adminuser varchar(30) latin1_swedish_ci
dateOfApproval date
byPassed binary(1)

Query:

$updateLevels="UPDATE flowdetailsdata set bypassed='0',adminNote='".$_REQUEST[$level]."',adminApp='".$_SESSION."', adminuser='".$_SESSION."',status='".$status."',dateOfApproval='".date('Y-m-d')."' where flowDetailsID='".$getAllLevels[$level]."' and formDataID='".$_REQUEST."'";

$adminDB->Execute($updateLevels);

$_REQUEST[$level] is text arean where admin writes his note

Are you sure it shouldn't be just $_REQUEST['Note'] ?

NO because there would be more than one level of admins and each has his own note.

<?php for($level=0;$level<count($getAllLevels);$level++){?>
<textarea  class="textfieldArea" style="width:160px; height:90px" name="Note[<?=$level?>]"><?=$getAllLevels[$level]['adminNote']?></textarea>

<?php  }?>

thank you all for your notes :)

If you do:

print_r($_GET); // get method
print_r($_POST); // post method

You can see everything that is posted, and whether or not you made a typo.

I am using $_REQUEST so I tried

print_r($_REQUEST);

And I got

Array ( [Note] => Array ( [0] => MY Note )

Note that I printed out the query with the value.

Then executed it in the database everything worked properly.

Can you check if the query returns an error ? Looks like you are using PDO, so check errorInfo.

No the query doesn't return errors and it updates all other fields.

a problem like yours appears if you are using $_REQUEST global array, instead you should use the $_POST[] global array and it's more secure for you..
aw you sql statement doesn't have an kind of error..
but usually we put the post or request variables (index) into another variable...
like :

$adminRequest = $_REQUEST['some index']

besides... sql statement should be written like this...

$sql= "UPDATE tablename SET something = '{$somethingelse}'"

try this and i'm sure every thing will go right

Here is a command in MySQL
UPDATE table_name colomn_name="updated_data",colomn_name="updated_data" (WHERE primary_key="a_data");
Try this structure.

Thanks for you help.

I inherited a bad code I fixed it and it is working :)

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.