# Blocking 2 users from overriding the XML

**URL:** <https://forum.kirupa.com/t/blocking-2-users-from-overriding-the-xml/230552>\
**Category:** Uncategorized\
**Created:** [June 27, 2007, 5:28am UTC](https://forum.kirupa.com/t/blocking-2-users-from-overriding-the-xml/230552 "2007-06-27T05:28:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mabulencia](https://avatars.discourse-cdn.com/v4/letter/m/f04885/32.png) [@mabulencia](https://forum.kirupa.com/u/mabulencia)\
**Post date:** [June 27, 2007, 5:28am UTC](https://forum.kirupa.com/t/blocking-2-users-from-overriding-the-xml/230552/1 "2007-06-27T05:28:13Z")

</div>

HELP!!!

How can I ensure that no 2 users in different browsers booking the same plot dont override each other?

Much appreciated.

[COLOR=darkred]index.php[/COLOR]  
[COLOR=darkred]\<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.1//EN” “[http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd](http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd)” \>[/COLOR]  
[COLOR=darkred]\<html xmlns=“[http://www.w3.org/1999/xhtml](http://www.w3.org/1999/xhtml)”\>[/COLOR]  
[COLOR=darkred]\<head\>\<title\>Plot booking\</title\>[/COLOR]  
[COLOR=darkred]\<link href=“screen.css” rel=“stylesheet” type=“text/css” /\>[/COLOR]  
[COLOR=darkred]\</head\>[/COLOR]

[COLOR=darkred]\<?php[/COLOR]

[COLOR=darkred]echo ‘\<body\>[/COLOR]  
[COLOR=darkred]\<table\>[/COLOR]  
[COLOR=darkred]\<tr\>[/COLOR]  
[COLOR=darkred]\<td\>[/COLOR]  
[COLOR=darkred]\<embed src=map.swf width=“600” height=“440”\>\</embed\>[/COLOR]  
[COLOR=darkred]\<form action=“processForm.php” method=“post”\>[/COLOR]  
[COLOR=darkred]\<fieldset\>’;[/COLOR]

[COLOR=darkred]function start\_tag1($parser1, $name1, $attrs1){[/COLOR]  
[COLOR=darkred]global $table\_string1;[/COLOR]  
[COLOR=darkred]$assign1=$attrs1[assigned];[/COLOR]  
[COLOR=darkred]if ($assign1==“no”){[/COLOR]  
[COLOR=darkred]$table\_string1 .= “\<option value=$attrs1[room]\>$attrs1[room]\</option\>”;[/COLOR]  
[COLOR=darkred]}[/COLOR]  
[COLOR=darkred]}[/COLOR]  
[COLOR=darkred]function end\_tag1($parser1, $name1){}[/COLOR]  
[COLOR=darkred]$parser1 = xml\_parser\_create();[/COLOR]  
[COLOR=darkred]xml\_parser\_set\_option($parser1, XML\_OPTION\_CASE\_FOLDING, 0);[/COLOR]  
[COLOR=darkred]xml\_set\_element\_handler($parser1, “start\_tag1”, “end\_tag1”);[/COLOR]  
[COLOR=darkred]$table\_string1 = “\<label\>Plot number: \<select type=text id=name name=name\>”;[/COLOR]  
[COLOR=darkred]xml\_parse($parser1, file\_get\_contents(“bookings.xml”)) or die(“Error parsing XML file”);[/COLOR]  
[COLOR=darkred]$table\_string1 .= “\</select\> \</label\>”;[/COLOR]  
[COLOR=darkred]echo $table\_string1;[/COLOR]

[COLOR=darkred]echo ‘\<label for=“student”\>Student number:\</label\>\<input type=“text” id=“student” name=“student” /\>[/COLOR]  
[COLOR=darkred]\<input type=“submit” name=“action” value=“book”/\>[/COLOR]  
[COLOR=darkred]\</fieldset\>[/COLOR]  
[COLOR=darkred]\</form\>[/COLOR]  
[COLOR=darkred]\</td\>[/COLOR]  
[COLOR=darkred]\<td\>[/COLOR]  
[COLOR=darkred]\<h1\>Plots not available:\</h1\>’;[/COLOR]

[COLOR=darkred]function start\_tag($parser, $name, $attrs){[/COLOR]  
[COLOR=darkred]global $table\_string;[/COLOR]  
[COLOR=darkred]$assign=$attrs[assigned];[/COLOR]  
[COLOR=darkred]if ($assign==“yes”){[/COLOR]  
[COLOR=darkred]$table\_string .= “\<tr\>\<td\>$attrs[room]\</td\>\<td\>$attrs[student]\</td\>\</tr\>”;[/COLOR]  
[COLOR=darkred]}[/COLOR]  
[COLOR=darkred]}[/COLOR]  
[COLOR=darkred]function end\_tag($parser, $name){}[/COLOR]  
[COLOR=darkred]$parser = xml\_parser\_create();[/COLOR]  
[COLOR=darkred]xml\_parser\_set\_option($parser, XML\_OPTION\_CASE\_FOLDING, 0);[/COLOR]  
[COLOR=darkred]xml\_set\_element\_handler($parser, “start\_tag”, “end\_tag”);[/COLOR]  
[COLOR=darkred]$table\_string = “\<table\>[/COLOR]  
[COLOR=darkred]\<tr\>\<th\>Plot no.\</th\>\<th\>Student\</th\>\</tr\>”;[/COLOR]  
[COLOR=darkred]xml\_parse($parser, file\_get\_contents(“bookings.xml”)) or die(“Error parsing XML file”);[/COLOR]  
[COLOR=darkred]$table\_string .= “\</table\>”;[/COLOR]  
[COLOR=darkred]echo $table\_string;[/COLOR]

[COLOR=darkred]echo ‘\</td\>[/COLOR]  
[COLOR=darkred]\</tr\>[/COLOR]  
[COLOR=darkred]\</table\>[/COLOR]  
[COLOR=darkred]\</body\>’;[/COLOR]  
[COLOR=darkred]?\>[/COLOR]

[COLOR=darkred]\</html\>[/COLOR]

[COLOR=darkslateblue]processForm.php[/COLOR]  
[COLOR=darkslateblue]\<!DOCTYPE HTML PUBLIC “-//W3C//DTD XHTML 1.1//EN” “[http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd](http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd)”\>[/COLOR]  
[COLOR=darkslateblue]\<html xmlns=“[http://www.w3.org/1999/xhtml](http://www.w3.org/1999/xhtml)”\>[/COLOR]  
[COLOR=darkslateblue]\<head\>[/COLOR]  
[COLOR=darkslateblue]\<title\>Plot booking processed\</title\>[/COLOR]  
[COLOR=darkslateblue]\<link href=“screen.css” rel=“stylesheet” type=“text/css” /\>[/COLOR]  
[COLOR=darkslateblue]\</style\>[/COLOR]  
[COLOR=darkslateblue]\<SCRIPT LANGUAGE=“JavaScript”\>\<!–[/COLOR]  
[COLOR=darkslateblue]setTimeout(‘self.close()’,5000);[/COLOR]  
[COLOR=darkslateblue]//–\>\</SCRIPT\>[/COLOR]  
[COLOR=darkslateblue]\</head\>[/COLOR]  
[COLOR=darkslateblue]\<body\>[/COLOR]  
[COLOR=darkslateblue]\<?[/COLOR]  
[COLOR=darkslateblue]$bookings = Array();[/COLOR]  
[COLOR=darkslateblue]function start\_element($parser, $name, $attrs){[/COLOR]  
[COLOR=darkslateblue]global $bookings;[/COLOR]  
[COLOR=darkslateblue]if($name == “booking”){[/COLOR]  
[COLOR=darkslateblue]array\_push($bookings, $attrs);[/COLOR]  
[COLOR=darkslateblue]}[/COLOR]  
[COLOR=darkslateblue]}[/COLOR]  
[COLOR=darkslateblue]function end\_element ($parser, $name){}[/COLOR]  
[COLOR=darkslateblue]$bookings\_string = file\_get\_contents(“bookings.xml”);[/COLOR]  
[COLOR=darkslateblue]$parser = xml\_parser\_create();[/COLOR]  
[COLOR=darkslateblue]xml\_set\_element\_handler($parser, “start\_element”, “end\_element”);[/COLOR]  
[COLOR=darkslateblue]xml\_parser\_set\_option($parser, XML\_OPTION\_CASE\_FOLDING, 0);[/COLOR]  
[COLOR=darkslateblue]xml\_parse($parser, $bookings\_string) or die(“Error parsing XML document.”);[/COLOR]  
[COLOR=darkslateblue]print “\<br /\>”;[/COLOR]  
[COLOR=darkslateblue]if($\_POST[‘action’] == “book”){[/COLOR]  
[COLOR=darkslateblue]array\_push($bookings, Array([/COLOR]  
[COLOR=darkslateblue]“room” =\> $\_POST[‘name’],[/COLOR]  
[COLOR=darkslateblue]“student” =\> $\_POST[‘student’],[/COLOR]  
[COLOR=darkslateblue]“assigned” =\> “yes”));[/COLOR]  
[COLOR=darkslateblue]$bookings\_final = $bookings;[/COLOR]  
[COLOR=darkslateblue]$plot = $\_POST[‘name’];[/COLOR]  
[COLOR=darkslateblue]$snumber = $\_POST[‘student’];[/COLOR]  
[COLOR=darkslateblue]}[/COLOR]  
[COLOR=darkslateblue]$write\_string = “\<bookings\>  
“;[/COLOR]  
[COLOR=darkslateblue]foreach($bookings\_final as $booking){[/COLOR]  
[COLOR=darkslateblue]if($booking[‘room’] != $\_POST[‘name’]){[/COLOR]  
[COLOR=darkslateblue]$bookings\_blank = Array();[/COLOR]  
[COLOR=darkslateblue]array\_push($bookings\_blank, $booking);[/COLOR]  
[COLOR=darkslateblue]$write\_string .= “\<booking room=”$booking[room]” student=”$booking[student]" assigned="$booking[assigned]" /\>";[/COLOR]  
[COLOR=darkslateblue]}[/COLOR]  
[COLOR=darkslateblue]}[/COLOR]  
[COLOR=darkslateblue]$write\_string .= "  
\<booking room="$booking[room]" student="$booking[student]" assigned="$booking[assigned]" /\>  
";[/COLOR]  
[COLOR=darkslateblue]$write\_string .= “\</bookings\>”;[/COLOR]  
[COLOR=darkslateblue]$fp = fopen(“bookings.xml”, “w+”);[/COLOR]  
[COLOR=darkslateblue]fwrite($fp, $write\_string) or die(“Error writing to file”);[/COLOR]  
[COLOR=darkslateblue]fclose($fp);[/COLOR]

[COLOR=darkslateblue]print “\<em\>Record added successfully.\<em\>\<br /\>”;[/COLOR]  
[COLOR=darkslateblue]print “\<h1\>Confirmation page\</h1\>\<br /\>”;[/COLOR]  
[COLOR=darkslateblue]print “\<p\>Plot no: \</p\>”;[/COLOR]  
[COLOR=darkslateblue]print $plot;[/COLOR]  
[COLOR=darkslateblue]print “\<p\>Booked by: \</p\>”;[/COLOR]  
[COLOR=darkslateblue]print $snumber;[/COLOR]  
[COLOR=darkslateblue]print “\<br/\>\<br/\>\<br/\>”;[/COLOR]  
[COLOR=darkslateblue]echo date(‘l dS \of F Y h:i:s A’);[/COLOR]  
[COLOR=darkslateblue]print “\<br/\>\<br/\>”;[/COLOR]  
[COLOR=darkslateblue]print “\<a href=javascript:self.close();\>Close this window\</a\>”;[/COLOR]  
[COLOR=darkslateblue]?\>[/COLOR]  
[COLOR=darkslateblue]\</body\>[/COLOR]  
[COLOR=darkslateblue]\</html\>[/COLOR]

[COLOR=darkorchid]bookings.xml[/COLOR]  
[COLOR=darkorchid]\<bookings\>[/COLOR]  
[COLOR=darkorchid]\<booking room=“001” student="" assigned=“no” /\>[/COLOR]  
[COLOR=darkorchid]\<booking room=“002” student="" assigned=“no” /\>[/COLOR]  
[COLOR=darkorchid]\<booking room=“003” student="" assigned=“no” /\>[/COLOR]  
[COLOR=darkorchid]\<booking room=“004” student="" assigned=“no” /\>[/COLOR]  
[COLOR=darkorchid]\<booking room=“005” student="" assigned=“no” /\>[/COLOR]  
[COLOR=darkorchid]\<booking room=“006” student="" assigned=“no” /\>[/COLOR]  
[COLOR=darkorchid]\<booking room=“007” student="" assigned=“no” /\>[/COLOR]  
[COLOR=darkorchid]\<booking room=“008” student="" assigned=“no” /\>[/COLOR]  
[COLOR=darkorchid]\<booking room=“009” student="" assigned=“no” /\>[/COLOR]  
[COLOR=darkorchid]\<booking room=“010” student="" assigned=“no” /\>[/COLOR]  
[COLOR=darkorchid]\</bookings\>[/COLOR]
