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.

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

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.