MySQL Forums
Forum List  »  Newbie

Locking records accross multiple php pages
Posted by: Antonio DePasquale
Date: July 16, 2014 12:08PM

Hi All,

So i'm using the innoDB engine on a database where I store... lets say information about our users.

Example
Name, extension, email


I have a php page where you can edit this information. The page works as follows.
After clicking an employee name, a page pops up where I
1. select the employee in question from the database
2. print the attributes to text feilds in a form for editing

Now, after making your changes, the user submits the form. The form returns to itself with some POST material and when if the page sees the submit button pressed, we update the record in the table.

My delema is this.

User A clicks "Antonio" to update his information
User B clicks "Antonio" to update his information

User A makes changes, and submits.
User B makes changes, and submits.

This makes User A's changes pointless.

I'd like to use the locking mechanism specific to innoDB but i think the transaction is lost when i click submit on the form.


Here is a sample code i threw together quick. The locking seems to not work because I can open two of these pages as seperate sessions and still over write the others changes
<?PHP
require_once('dbconnect.php');
if (!isset($_GET['emp_id'])){
$snoopy->autocommit(FALSE);
$SQL = "SELECT * FROM employees WHERE fname = 'Antonio' FOR UPDATE";
$result = $snoopy->query($SQL) or die("Error executing Query: " .$snoopy->error);

$depts=mysqli_fetch_array($result);
echo "<a href='/testing.php?emp_id=".$depts['emp_id']."'>hi</a>";

} else {
$SQL = "UPDATE employees SET lname='depasquale' WHERE emp_id = ".$_GET['emp_id']."";
$snoopy->query($SQL) or die("Error executing Query: " .$snoopy->error);
$snoopy->commit();
}


?>

Options: ReplyQuote


Subject
Written By
Posted
Locking records accross multiple php pages
July 16, 2014 12:08PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.