Forum Moderators: coopster

Message Too Old, No Replies

Trip Report PHP

         

outdoorxtreme1

5:02 pm on Oct 18, 2005 (gmt 0)

10+ Year Member



I am a newbie to PHP. How would I go about creating a trip report submission.

Any help would be greatly appreciated. I want to create trip reports for my canoe club webpage.

Thanks in advance.

Dustin

[edited by: jatar_k at 5:28 pm (utc) on Oct. 18, 2005]
[edit reason] no urls thanks [/edit]

AlexK

6:47 pm on Oct 31, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



outdoorxtreme1:
See anything wrong here?

Unless I have mis-read your code (very possible!) it is submitting an error msg whether there is an error or not (
echo()
statements at top).

Some long-term advice, with particular value to future maintenance:

  1. Modularise your code, and comment each section liberally.

    You may know what each section is for at the moment, but will have difficulty remembering in the future. Write the comments as if for some other programmer coming to your code for the first time. This has proved a life-saver for me recently.

  2. At the top clean all user-submitted variables.

    You should never use any

    $_REQUEST[]
    variables (
    $_POST[], $_GET[], $_COOKIE[]
    ) directly in your code. This is a real pain to do, but will save much future grief. Try to understand that there are people out there that do nothing else other than trying to "own" your server through your code. It is particularly important with user-submitted info which is then stored in a database.
  3. Next, error-check all
    $_REQUEST[]
    variables.

    Error-checking is an integral part of the code, and the best place for it is at the top. Have a global error boolean (== TRUE means that there has been an error) and per-section error booleans.


A suggestion for highlighting the error:

Use CSS. Declare 2 styles which are nearly identical:

- normal_style 
- error_style
the sole difference being that the second has a different background colour and/or border. Then switch between the 2 styles according to the value of the per-section error boolean (the ternary operator is useful here!):
<?php
echo "<input type='text' class='". ( $per_section_error_boolean )? "error_style" : "normal_style" ) ."' />";
?>

outdoorxtreme1

7:04 pm on Oct 31, 2005 (gmt 0)

10+ Year Member



Here is what I came up with:

It seems to work ok but what ever month, day and year it is, it puts it in the drop down menu double and out of order.

<td valign="top" colspan="2" style="white-space:nowrap;"><strong>Trip Start:</strong><br />
<select name="TSpickMonth" size="1">

<option value="<? echo date('M');
?>"><? echo date('M');?></option>
<option value="January">Jan</option>
<option value="Feburary">Feb</option>
<option value="March">Mar</option>
<option value="April">Apr</option>
<option value="May">May</option>
<option value="June">Jun</option>
<option value="July">Jul</option>
<option value="August">Aug</option>
<option value="September">Sep</option>
<option value="October">Oct</option>
<option value="November">Nov</option>
<option value="December">Dec</option>
</select>

<select name="TSpickDay" size="1">

<option value="<? echo date('d');
?>"><? echo date('d');?></option>
<option value="1">1</option>
<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="TSpickYear" size="1">

<option value="<? echo date('Y');
?>"><? echo date('Y');?></option>
<option value="2002">2002</option>
<option value="2003">2003</option>
<option value="2004">2004</option>
<option selected="selected" value="2005">2005</option>
<option value="2006">2006</option>
</select>

</td>

jatar_k

7:32 pm on Oct 31, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



see if you can get this one to work
Dynamic Date Selector [webmasterworld.com] message 5

outdoorxtreme1

7:41 pm on Oct 31, 2005 (gmt 0)

10+ Year Member



Sweet. Works good. Do I do an array like the day for the year?

jatar_k

7:44 pm on Oct 31, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you can

though I just added them everytime for the years I needed since there were never many and it would always default to the top one which I set as the current year

outdoorxtreme1

7:48 pm on Oct 31, 2005 (gmt 0)

10+ Year Member



What do i need to put in the brackets?

$year = $today[' ']

outdoorxtreme1

7:55 pm on Oct 31, 2005 (gmt 0)

10+ Year Member



I tried year and it didnt seem to like that.

outdoorxtreme1

7:56 pm on Oct 31, 2005 (gmt 0)

10+ Year Member



Sorry. I forgot the ;

outdoorxtreme1

8:05 pm on Oct 31, 2005 (gmt 0)

10+ Year Member



I didn't notice this before but I am getting these error messages even if there is an error message or not:

SORRY: There is a problem with information you have submitted:

Please complete your report and "Submit" again...

<?
$errmsg = '';

$errmsg .= '<font color=#FF0000>SORRY: There is a problem with information you have submitted:</font>';
$errmsg .= '<ul>';

if (empty($_POST['triplocation'])) {
$errmsg .= '<font color=#FF0000><li>Your report has no [trip location]</li></font><br>';
}

if (empty($_POST['author'])) {
$errmsg .= '<font color=#FF0000><li>Please identify the [trip report author]</li></font><br>';
}

if (empty($_POST['report'])) {
$errmsg .= '<font color=#FF0000><li>Please fill in your [trip report]</li></font><br>';
}

$errmsg .= '</ul>';
$errmsg .= '<font color=#FF0000>Please complete your report and "Submit" again...<br></font>';

if (!empty($errmsg)) {
include 'form.php';

} else {

outdoorxtreme1

8:18 pm on Oct 31, 2005 (gmt 0)

10+ Year Member



do I need to use some kind of if statement?

jatar_k

8:57 pm on Oct 31, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



show me the line or two that echo's your $errmsg

outdoorxtreme1

3:11 pm on Nov 1, 2005 (gmt 0)

10+ Year Member



<?
$errmsg .= '';

{
$errmsg .= '<font color=#FF0000>SORRY: There is a problem with information you have submitted:</font>';
$errmsg .= '<ul>';
}

if (empty($_POST['triplocation'])) {
$errmsg .= '<font color=#FF0000><li>Your report has no [trip location]</li></font><br>';
}

if (empty($_POST['author'])) {
$errmsg .= '<font color=#FF0000><li>Please identify the [trip report author]</li></font><br>';
}

if (empty($_POST['report'])) {
$errmsg .= '<font color=#FF0000><li>Please fill in your [trip report]</li></font><br>';
}

$errmsg .= '</ul>';
$errmsg .= '<font color=#FF0000>Please complete your report and "Submit" again...<br></font>';

if (!empty($errmsg)) {
include 'form.php';

} else {

jatar_k

3:14 pm on Nov 1, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



ah, but that isn't where you are echo'ing it

there should be a line in form.php that echo's it and may have an if statement around it already

outdoorxtreme1

3:41 pm on Nov 1, 2005 (gmt 0)

10+ Year Member



opps. sorry.

Here is the code from form.php

<?
if (isset($errmsg) &&!empty($errmsg)) {
echo '<p>',$errmsg;
}

now
?>

jatar_k

4:02 pm on Nov 1, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



that's what I figured. What we did with appending those strings to that var is now it will never be empty so we just need to put those two lines into that if statement you have there and we will be fine

if (isset($errmsg) &&!empty($errmsg)) {
echo '<p>',$errmsg;
echo '</ul>';
echo '<font color=#FF0000>Please complete your report and "Submit" again...<br></font>';
}

that should do it

outdoorxtreme1

4:21 pm on Nov 1, 2005 (gmt 0)

10+ Year Member



what is the "now" at the bottom of the code?

outdoorxtreme1

4:52 pm on Nov 1, 2005 (gmt 0)

10+ Year Member



How do I get the actual month name for data that will be entered to MySQL from this month select?

<select name="TSpickMonth" size="1">
<? for ($i=1;$i<=12;$i++) {?><? echo "<option value=\"$i\""; if ($i == $month) echo " selected"; echo ">" . $mtharr[$i-1] . "</option>"; } ?>
</select>

jatar_k

5:46 pm on Nov 1, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>> what is the "now" at the bottom of the code?

I have no clue it was in what you pasted

>> get month name

I see it is just the number at the moment.

as far as dates go I always store the numeric representation and then worry about how I want displayed when I output it. That makes it a lot easier if I need to do any math with the dates at any point.

outdoorxtreme1

6:42 pm on Nov 1, 2005 (gmt 0)

10+ Year Member



Is there a message on the forum somewhere that I could find out how to output a month name from th month number?

jatar_k

8:39 pm on Nov 1, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



date [ca3.php.net] would work, you just fee it the timestamp which you can create from the day, month and year from your database

there is an example on the page I linked that shows how to use mktime inside the date function

outdoorxtreme1

8:59 pm on Nov 1, 2005 (gmt 0)

10+ Year Member



Am I on the right track?

$startdate = date(mktime($row['TSpickMonth'] . ' ' . $row['TSpickDay'] . ', ' . $row['TSpickYear']));

jatar_k

9:24 pm on Nov 1, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



close

for mktime you need these arguments

int mktime ( [int hour [, int minute [, int second [, int month [, int day [, int year [, int is_dst]]]]]]] )

so you need 0,0,0 before month,day, year

for date it takes 2 arguments, the second will be your mktime part

the first will be your pattern for your date, look at the date function page for all the patterns

outdoorxtreme1

9:31 pm on Nov 1, 2005 (gmt 0)

10+ Year Member



Got it.

$startdate = date("F d Y", mktime(0,0,0,$row['TSpickMonth'],$row['TSpickDay'],$row['TSpickYear']));

I am having trouble getting the comma in for the date.

Right now it shows:
November 1 2005

Want it to be:
November 1, 2005

outdoorxtreme1

9:36 pm on Nov 1, 2005 (gmt 0)

10+ Year Member



Nevermind. I got it. I was trying to add it to the mktime data.

jatar_k

9:36 pm on Nov 1, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



just add it into the pattern

"F d, Y"

outdoorxtreme1

3:50 pm on Nov 4, 2005 (gmt 0)

10+ Year Member



I made a field to enter a photo slideshow website address. When I view the report only www shows up and the rest of the address is not there

outdoorxtreme1

4:09 pm on Nov 4, 2005 (gmt 0)

10+ Year Member



I was able to get that to work but now if I have www.photosite.com for a link it wants to open it as part of my current page. Can anyone help?

jatar_k

4:27 pm on Nov 4, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



in the a tag use

target="_new"

that will make it open in a new window

outdoorxtreme1

4:59 pm on Nov 4, 2005 (gmt 0)

10+ Year Member



I'm trying to get this to work. What am I doing wrong?

if (!empty($row['photolink'])) echo '<strong>Photo Slideshow Link: </strong>
<a href="javascript:void(0);" onclick="fullScreen(',$row['photolink'],');">',$row['photolink'],'</a><br>';

I need it output like this:

<a href="javascript:void(0);" onclick="fullScreen('http://www.myphotoalbum.com');">http://www.myphotoalbum.com</a>

Here is what it is currently:

<a href="javascript:void(0);" onclick="fullScreen(http://www.myphotoalbum.com);">http://www.myphotoalbum.com</a>

How do I get the ' ' for the address?

ergophobe

5:15 pm on Nov 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You have a quote matching/contatenation problem.

echo '<strong>Photo... fullScreen(',$row['photolink'],');"> ',$row['photolink'],'</a><br>';

The concatenation operator is a period

This 158 message thread spans 6 pages: 158