Hi,
I would like to make a form which easily adds entries to a table of events, so it wil add the date, event title, event details, and event location and also a post code,
Ok,
i have a script which i think could easily do what i want but i would need some advice about converting
this script:
PHP Code:
<html>
<body>
<!-- 123456 -->
<?php
// Set these to get the guestbook more personal.
// ========================================
$gbfile = "gbook.txt"; // The file that all guestbook entrys should be saved in.
$thisfile = "guestbook.php"; // page it re-directs to when you save or post.
$dateshow = "l jS F Y - H:i:s"; // Decides how the date should be shown. http://www.w3schools.com/php/func_date_date.asp
$username = "admin"; // Admin username.
$password = "calm"; // Admin password.
$wrongpass = "Not logged in! WRONG INFO"; // Text to show when the wrong password has been entered.
$wrongname = "Not logged in! WRONG INFO"; // Text to show when the wrong username has been entered.
$thankstxt = "<meta http-equiv='refresh' content='2;URL=$thisfile'><p>Thank you for signing CALM's Guestbook. Your comments are apprieciated.<br>You will be sent back in a few seconds. If not click <a href='$thisfile'>here</a></p>"; // The text that the user will see after entering something in the guestbook.
$errornoname = "<meta http-equiv='refresh' content='1;URL=$thisfile'><p>ERROR! You have to enter a name!<br>You will be sent back in a few seconds. If not click <a href='$thisfile'>here</a></p>"; // Text to print out when no name has been entered in the entry.
$errornomsg = "<meta http-equiv='refresh' content='1;URL=$thisfile'><p>EROR! You have to enter a message!<br>You will be sent back in a few seconds. If not click <a href='$thisfile'>here</a></p>"; // Text to print out when no message has been entered in the entry.
$gbedited = "<meta http-equiv='refresh' content='1;URL=$thisfile'><p>Guestbook has been edited!<br>You will be sent back in a few seconds. If not click <a href='$thisfile'>here</a></p>"; // Text to print out when guestbook has been edited.
// ========================================
// Do not change under here
// ========================================
$gbpage = "$_SERVER[PHP_SELF]";
$date = date("$dateshow");
$name = htmlentities(strip_tags($_POST['name']));
$email = htmlentities(strip_tags($_POST['email']));
$homepage = htmlentities(strip_tags($_POST['homepage']));
$message = nl2br(htmlentities(strip_tags($_POST['message'])));
$message = str_replace(array("\r", "\n"), '', $message);
$message = wordwrap($message, 75, "<br />", true);
$printfull = "<table width=\"400\" border=\"1\" align=\"center\" bordercolor=\"#CCCCCC\"><tr><td width=\"80\"><strong>Date:</strong></td><td width=\"320\">$date</td></tr><tr><td><strong>Name:</strong></td><td>$name</td></tr><tr><td><strong>Email:</strong></td><td><a href=\"mailto:$email\">$email</a></td></tr><tr><td><strong>Homepage:</strong></td><td><a href=\"$homepage\" target=\"_blank\">$homepage</a></td></tr><tr><td><strong>Message:</strong></td><td>$message</td></tr></table><br> \n";
$printnoemail = "<table width=\"400\" border=\"1\" align=\"center\" bordercolor=\"#CCCCCC\"><tr><td width=\"80\"><strong>Date:</strong></td><td width=\"320\">$date</td></tr><tr><td><strong>Name:</strong></td><td>$name</td></tr><td><strong>Homepage:</strong></td><td><a href=\"$homepage\" target=\"_blank\">$homepage</a></td></tr><tr><td><strong>Message:</strong></td><td>$message</td></tr></table><br> \n";
$printnopage = "<table width=\"400\" border=\"1\" align=\"center\" bordercolor=\"#CCCCCC\"><tr><td width=\"80\"><strong>Date:</strong></td><td width=\"320\">$date</td></tr><tr><td><strong>Name:</strong></td><td>$name</td></tr><tr><td><strong>Email:</strong></td><td><a href=\"mailto:$email\">$email</a></td></tr><tr><td><strong>Message:</strong></td><td>$message</td></tr></table><br> \n";
$printnoemailpage = "<table width=\"400\" border=\"1\" align=\"center\" bordercolor=\"#CCCCCC\"><tr><td width=\"80\"><strong>Date:</strong></td><td width=\"320\">$date</td></tr><tr><td><strong>Name:</strong></td><td>$name</td></tr><tr><td><strong>Message:</strong></td><td>$message</td></tr></table><br> \n";
// ========================================
// SCRIPT START !!!
// ========================================
switch($_GET['id'])
{
default:
?>
<table align="center"><form action="<?php echo $gbpage; ?>?id=1" method="post" name="submitform">
<tr><td><strong>Name:</strong></td><td><input type="text" name="name" size="40" maxlength="50" title="This Guestbook is moderated and any offensive or otherwise unaceptable comments will be REMOVED!" />
<a href="#" title="This is the name that will be displayed with your comment.">[?]</a></td></tr>
<tr><td><strong>Email:</strong></td><td><input type="text" name="email" size="40" maxlength="50" title="This Guestbook is moderated and any offensive or otherwise unaceptable comments will be REMOVED!" />
<a href="#" title="Your email address will be displayed with your comment">[?]</a></td></tr>
<tr><td><strong>Homepage:</strong></td><td><input type="text" name="homepage" size="40" maxlength="50" value="http://" title="This Guestbook is moderated and any offensive or otherwise unaceptable comments will be REMOVED!" />
<a href="#" title="If you have a website, you can type it here to be displayed with you comment.">[?]</a></td></tr>
<tr><td valign="top"><strong>Message:</strong></td><td><textarea name="message" cols="30" rows="7" class="gbwarn" title="This Guestbook is moderated and any offensive or otherwise unaceptable comments will be REMOVED!"></textarea></td></tr>
<tr><td></td><td><input type="submit" name="submit" value="Submit" title="Submit you comment."></td></tr>
</form></table><br>
<?php
$gb = file($gbfile);
$gb = array_reverse($gb);
foreach ($gb as $guestbook) { echo stripslashes($guestbook); }
break;
case 1:
if($name == "")
{ echo $errornoname; }
elseif($message == "")
{ echo $errornomsg; }
elseif($email == "")
{
if($homepage == "" || $homepage == "http://")
{
$writeinfo = $printnoemailpage;
$printer = fopen($gbfile,"a");
fwrite($printer,$writeinfo);
fclose($printer);
echo $thankstxt;
}
else
{
$writeinfo = $printnoemail;
$printer = fopen($gbfile, 'a');
fwrite($printer,$writeinfo);
fclose($printer);
echo $thankstxt;
}
}
elseif($homepage == "" || $homepage == "http://")
{
$writeinfo = $printnopage;
$printer = fopen($gbfile, 'a');
fwrite($printer,$writeinfo);
fclose($printer);
echo $thankstxt;
}
else
{
$writeinfo = $printfull;
$printer = fopen($gbfile, 'a');
fwrite($printer,$writeinfo);
fclose($printer);
echo $thankstxt;
}
break;
case 2:
?>
<table align="center"><form action="<?php echo $gbpage; ?>?id=3" method="post" name="submitform">
<tr><td><strong>Username:</strong></td><td><input type="text" name="adminname" size="20"></td></tr>
<tr><td><strong>Password:</strong></td><td><input type="password" name="adminpass" size="20"></td></tr>
<tr><td></td><td><input type="submit" name="submit" value="Login"></td></tr>
</form></table>
<?php
break;
case 3:
if($_POST["adminname"] == $username) { if($_POST["adminpass"] == $password) {
?>
<table align="center"><form name="guestbookedit" method="post" action="<?php echo $gbpage; ?>?id=4">
<tr><td><textarea name="gbedit" cols="65" rows="30" wrap="off">
<?php
$gb = file("$gbfile");
$gb = array_values($gb);
foreach ($gb as $guestbook) { echo stripslashes($guestbook); }
?>
</textarea></td></tr>
<tr><td>Enter admin password to edit entrys: <input type="password" name="psw" size="20"></td></tr>
<tr><td><input type="submit" name="Submit" value="Save"><input type="reset" name="Reset" value="Reset"></td></tr>
</form></table>
<?php
} else { echo "$wrongpass"; } }
else { echo "$wrongname"; }
break;
case 4:
if($_POST["psw"] == $password)
{
$writeinfo = $_POST['gbedit'];
$writeinfo = stripslashes($writeinfo);
$printer = fopen($gbfile, 'w');
fwrite($printer,$writeinfo);
fclose($printer);
echo $gbedited;
}
else { echo "$wrongpass"; }
break;
}
// ========================================
// SCRIPT END !!!
?>
<!-- 654321 -->
<p align="left">To be removed: <a href="<?php echo $gbpage; ?>?id=2">Admin</a></p>
</body>
</html>
This script appends entries in a like template layout, in a flat txt file.
i need this script to basically do this but with differant fields and in a differant template...
ok heres the form which i would like to use.
Code:
<form method="post" action="eventsadd.php">
Date of event:
<select name="eventday">
<option value="mon">Monday</option>
<option value="tue">Tuesday</option>
<option value="wed">Wednesday</option>
<option value="thu">Thursday</option>
<option value="fri">Friday</option>
<option value="sat">Saturday</option>
<option value="sun">Sunday</option>
</select>
<select name="eventdate">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
<select name="eventmonth">
<option value="jan">January</option>
<option value="feb">February</option>
<option value="mar">March</option>
<option value="apr">Aprirl</option>
<option value="may">May</option>
<option value="jun">June</option>
<option value="jul">July</option>
<option value="aug">August</option>
<option value="sep">September</option>
<option value="oct">October</option>
<option value="nov">November</option>
<option value="dec">December</option>
</select>
<br />
<br />
<br />
Event title: <input type="text" size="25" name="eventtitle" />
<br />
<br />
Event details: <textarea name="eventdetails" cols="45" rows="5">Details about events.</textarea>
<br />
<br />
Event location: <textarea name="eventlocation" cols="40" rows="4">Event loction</textarea>
<br />
Postcode of location: <input type="text" size="8" name="eventpostcode" /> This will be used for google maps link to help people to find the event.
</form>
And i would like the template something like this:
PHP Code:
<div class="curlycontainer">
<div class="innerdiv">
<span style="float: left"> $fulldateofevent </span>
$eventtitle
<br />
<div> $eventdetails </div>
<br />
<span> $eventlocation ~ <a href="http://maps.google.co.uk/maps?f=d&hl=en&saddr=&daddr= $POSTCODE &sll=51.548476,-1.838099&sspn=0.009447,0.019484&ie=UTF8&z=16&iwloc=addr&om=1">Google Maps</a></span>
</div>
</div>
Could anyone help... im a little lost..
Thanks
TP for whoever can help me.... if thats any incentive,
Dan