Ok, this is one of them posts where I know what I want to do but dont have the foggyest how to start it or even where to look to get any tips about it.
I’ll briefly describe what I am hoping to achieve:
This is for a personal website, I am trying to organise a section on my website to allow people to ‘Put There Name’ against a hotel room.
Now what I mean by this is I have a list of 20 rooms with prices and descriptions with an image by it. What I hope to achieve is to have an input box and a submit button by each individual Room.
If one of my guests likes the look of the room they can add there name in the input box and click submit. This will then remove the input box and submit button from that particular room and instead replace it with the Guests name. This will then show to all other visitors on the site who is interested in a particular room, first come first serve kinda thing! It does not need to act in anyway as a booking feature or anything, but It is mainly to act as an aid to help myself and partner work out what guests we will have staying in which rooms!
Make any sense?> I know it may sound like a daft idea and I am going to be playing around with certain ways, even figure out if it can be done or not! But just hoping for a bit of inspiration!
Cheers for any suggestions or comments!
[code=php]<?php
$Fname = $_POST["Fname"];
if (!isset($_POST['submit'])) {
?>
<html>
<head>
<title>Test</title>
</head>
<body>
<form method="post" action="<?php echo $PHP_SELF;?>">
Put your name to this room!: <input type="text" size="12" maxlength="12" name="Fname"> <input type="submit" value="submit" name="submit">
</form>
<?
} else {
echo "This room is sort after by ".$Fname."<br />";
}
?> [/code]
[code=php]
<?php
<?php
class PropertyHelper {
private $file;
public $properties;
function __construct($file) {
$this->file = $file;
$lines = file($file);
if($lines) {
$first = true;
foreach($lines as $line) {
$current = explode('=',$line,2);
if(!strpbrk($current[0], '#')) {
$props = array($current[0]=>trim($current[1]));
if($current[1] != NULL && $current[1] != ' ') {
if($first) {
$this->properties = $props;
$first = false;
} else {
$this->properties = array_merge($this->properties, $props);
}
}
}
}
} else {
throw new Exception("File '$file' not found");
}
}
public function getProperty($prop) {
return $this->properties[$prop];
}
public function getAllProperties() {
return $this->properties;
}
public function setProperty($name, $value) {
$newContents = "";
$lines = file($this->file);
if($lines) {
foreach($lines as $line) {
$current = explode('=', $line, 2);
if($current[0] == $name) {
$newContents .= $name.'='.$value."rn";
} else {
$newContents .= $line;
}
}
}
$fh = fopen($this->file, 'w');
fwrite($fh, $newContents);
fclose($fh);
return true;
}
}
?>
[/code]
<i>
</i>room1=Jennifer
room2=
room3=Jason Houle
room4=
[code=php]
<?php
include($_SERVER['DOCUMENT_ROOT'].'/resources/php/PropertyHelper.class.php');
$ph = new PropertyHelper('test.txt');
$room = 'room1';
$reserved = $ph->getProperty($room);
?>
<?php
$Fname = $_POST["Fname"];
if (isset($_POST['submit'])) {
$ph->setProperty($room, $Fname);
}
?>
<html>
<head>
<title>Test</title>
</head>
<body>
<?php
if($reserved != '' && $reserved != NULL) {
echo "This room is sort after by ".$reserved."<br />";
} else if(isset($_POST['submit'])) {
echo "This room is sort after by ".$Fname."<br />";
} else {
?>
<form method="post" action="<?php echo $PHP_SELF;?>">
Put your name to this room!: <input type="text" size="12" maxlength="12" name="Fname"> <input type="submit" value="submit" name="submit">
</form>
<?php
}
?>
</body>
</html>
[/code]
[code=php]
function __construct($file) {
[/code]
[code=php]
function PropertyHelper($file) {
[/code]
[code=php]<?php
class PropertyHelper {
function __construct($file) {
$this->file = $file;
$lines = file($file);
if($lines) {
$first = true;
foreach($lines as $line) {
$current = explode('=',$line,2);
if(!strpbrk($current[0], '#')) {
$props = array($current[0]=>trim($current[1]));
if($current[1] != NULL && $current[1] != ' ') {
if($first) {
$this->properties = $props;
$first = false;
} else {
$this->properties = array_merge($this->properties, $props);
}
}
}
}
} else {
throw new Exception("File '$file' not found");
}
}
function getProperty($prop) {
return $this->properties[$prop];
}
function getAllProperties() {
return $this->properties;
}
function setProperty($name, $value) {
$newContents = "";
$lines = file($this->file);
if($lines) {
foreach($lines as $line) {
$current = explode('=', $line, 2);
if($current[0] == $name) {
$newContents .= $name.'='.$value."rn";
} else {
$newContents .= $line;
}
}
}
$fh = fopen($this->file, 'w');
fwrite($fh, $newContents);
fclose($fh);
return true;
}
}
?> [/code]
[CODE]rse error: syntax error, unexpected T_NEW in /home/c26bran/public_html/wedding/PropertyHelper.class.php on line 25[/CODE]
[code=php]else {
throw new Exception("File '$file' not found");
} [/code]
[CODE]Warning: fwrite(): supplied argument is not a valid stream resource in /home/c26bran/public_html/wedding/PropertyHelper.class.php on line 49
Warning: fclose(): supplied argument is not a valid stream resource in /home/c26bran/public_html/wedding/PropertyHelper.class.php on line 50
[/CODE]
[CODE]
room1=
room2=
room3=
room4=
room5=
[/CODE]
<i>
</i>function __construct($file) {
<i>
</i>function PropertyHelper($file) {
<i>
</i>throw new Exception....
[code=php]<?php
class PropertyHelper {
function PropertyHelper($file) {
$this->file = $file;
$lines = file($file);
if($lines) {
$first = true;
foreach($lines as $line) {
$current = explode('=',$line,2);
if(!strpbrk($current[0], '#')) {
$props = array($current[0]=>trim($current[1]));
if($current[1] != NULL && $current[1] != ' ') {
if($first) {
$this->properties = $props;
$first = false;
} else {
$this->properties = array_merge($this->properties, $props);
}
}
}
}
} else {
throw new Exception("File '$file' not found");
}
}
function getProperty($prop) {
return $this->properties[$prop];
}
function getAllProperties() {
return $this->properties;
}
function setProperty($name, $value) {
$newContents = "";
$lines = file($this->file);
if($lines) {
foreach($lines as $line) {
$current = explode('=', $line, 2);
if($current[0] == $name) {
$newContents .= $name.'='.$value."rn";
} else {
$newContents .= $line;
}
}
}
$fh = fopen($this->file, 'w');
fwrite($fh, $newContents);
fclose($fh);
return true;
}
}
?> [/code]
[CODE]Parse error: syntax error, unexpected T_NEW in /home/c26bran/public_html/wedding/PropertyHelper.class.php on line 25[/CODE]
<i>
</i> else {
throw new Exception("File '$file' not found");
}
[code=php]<?php
include($_SERVER['DOCUMENT_ROOT'].'/wedding/PropertyHelper.class.php');
$ph = new PropertyHelper('rooms.txt');
$room = 'room1';
$reserved = $ph->getProperty($room);
?>
<?php
$Fname = $_POST["Fname"];
if (isset($_POST['submit'])) {
$ph->setProperty($room, $Fname);
}
?>
<html>
<head>
<title>Test</title>
</head>
<body>
<?php
if($reserved != '' && $reserved != NULL) {
echo "This room is sort after by ".$reserved."<br />";
} else if(isset($_POST['submit'])) {
echo "This room is sort after by ".$Fname."<br />";
} else {
?>
<form method="post" action="<?php echo $PHP_SELF;?>">
Put your name to this room!: <input type="text" size="12" maxlength="12" name="Fname"> <input type="submit" value="submit" name="submit">
</form>
<?php
}
?>
</body>
</html> [/code]
<i>
</i>isset($_POST['submit'])
<i>
</i>$_POST['submit'] == 'submit'
0.1.9 — BETA 5.28