Reply
Help needed to convert this simple guest book into a events, adder..REALLY EASY!....
Old 05-01-2007, 02:24 PM SOLVED, please ignore or delete
dansgalaxy's Avatar
Eat, Sleep, Code

Posts: 6,173
Name: Dan
Location: Swindon
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($message75"<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
__________________
Personal UK Webhosting
Get 25% of ANY shared package for life ~ Promo: webmaster-talk (only for members!)

Last edited by dansgalaxy : 05-01-2007 at 05:36 PM.
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
When You Register, These Ads Go Away!
Old 05-01-2007, 05:37 PM Re: Help needed to convert this simple guest book into a events, adder..REALLY EASY!.
dansgalaxy's Avatar
Eat, Sleep, Code

Posts: 6,173
Name: Dan
Location: Swindon
This is solved please remove thread.... or somin.
__________________
Personal UK Webhosting
Get 25% of ANY shared package for life ~ Promo: webmaster-talk (only for members!)
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 05-01-2007, 05:42 PM Re: Help needed to convert this simple guest book into a events, adder..REALLY EASY!.
solomongaby's Avatar
Webmaster Talker

Latest Blog Post:
How Do You Find Music Online ?
Posts: 522
Name: Gabe Solomon
Location: Romania
i think something like this coul work

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");
$eventdayhtmlentities(strip_tags($_POST['eventday']));
$eventdatehtmlentities(strip_tags($_POST['eventdate']));
$eventmonthhtmlentities(strip_tags($_POST['eventmonth']));
$fulldateofevent=''.$eventday.'-'.$eventdate.'-'.$eventmonth.'';
$eventtitlehtmlentities(strip_tags($_POST['eventtitle']));
$eventdetailhtmlentities(strip_tags($_POST['eventdetail']));
$eventlocationhtmlentities(strip_tags($_POST['eventlocation']));
$POSTCODE=$_POST['eventpostcode']
// ========================================
// SCRIPT START !!!
// ========================================
switch($_GET['id'])
{
default:
 
?>
 <form action="<?php echo $gbpage?>?id=1" method="post" name="submitform">
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>
 <?php
 $gb 
file($gbfile);
 
$gb array_reverse($gb);
 foreach (
$gb as $guestbook) { echo stripslashes($guestbook); }
break;
case 
1:
  
$writeinfo '
   <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>  
  '
;
  
$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>

it was done in the post editor so it still might have a few bug.
Hope you get the general ideea
__________________
If you like my posts ... TK is appreciated:)
Web Directory | Blog
solomongaby is offline
Reply With Quote
View Public Profile Visit solomongaby's homepage!
 
Old 05-01-2007, 06:37 PM Re: Help needed to convert this simple guest book into a events, adder..REALLY EASY!.
dansgalaxy's Avatar
Eat, Sleep, Code

Posts: 6,173
Name: Dan
Location: Swindon
I ended up doing it way easier, just using fopen/fwrite etc and just made it append...

http://calm.dansgalaxy.co.uk/events.php so now i just go to a form and add them easily...
Dan
__________________
Personal UK Webhosting
Get 25% of ANY shared package for life ~ Promo: webmaster-talk (only for members!)
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 05-02-2007, 07:10 AM Re: Help needed to convert this simple guest book into a events, adder..REALLY EASY!.
solomongaby's Avatar
Webmaster Talker

Latest Blog Post:
How Do You Find Music Online ?
Posts: 522
Name: Gabe Solomon
Location: Romania
i am glad you were able to sort it out .... 1 small request ... can you put
[ SOLVED ] to the end of the first topic title ? thank you
__________________
If you like my posts ... TK is appreciated:)
Web Directory | Blog
solomongaby is offline
Reply With Quote
View Public Profile Visit solomongaby's homepage!
 
Old 05-02-2007, 11:17 AM Re: Help needed to convert this simple guest book into a events, adder..REALLY EASY!.
dansgalaxy's Avatar
Eat, Sleep, Code

Posts: 6,173
Name: Dan
Location: Swindon
LOOK! thats all im saying...... i did... and i put a post after it... and then u decieded to post :|

Dan

NOTE: THIS IS MY 1000th POST!!

Am i right in saying this means mt tp power is 12? or am i wrong?...
__________________
Personal UK Webhosting
Get 25% of ANY shared package for life ~ Promo: webmaster-talk (only for members!)

Last edited by dansgalaxy : 05-02-2007 at 11:19 AM.
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 05-02-2007, 01:03 PM Re: Help needed to convert this simple guest book into a events, adder..REALLY EASY!.
solomongaby's Avatar
Webmaster Talker

Latest Blog Post:
How Do You Find Music Online ?
Posts: 522
Name: Gabe Solomon
Location: Romania
congratulations on you're 1000th post

sorry i didnt saw that you changed the title
it seems that changing the first topic tittle would not change the overall thread title


PS : what does tp power is 12 mean?
__________________
If you like my posts ... TK is appreciated:)
Web Directory | Blog