Echo problem

Hi all, I am trying to create a simple form which will eventually store the inputted values in a database and tracks data for travelling health professionals. The form looks OK to me but it does not appear to storing values for mileages and bonus but is working ok for the date and clinic. I have been over the code about 20 times but Im obviously missing something. Hoping it is just a silly typo!

[code]

Simple HTML Form label { font-weight: bold; color: #300ACC; } Please enter information in the form below:
<p><label>Date: <input type="date" name="Date"/></label></p>

<p><label>Clinic: <input type="text" name="Clinic" size ="20" maxlength="30"/></label></p>

<p><label>Google Miles: <input type="number" name="Claimed Mileage" min="0" max="500"/></label></p>

<p><label>Actual Miles: <input type="number" name="Actual Mileage" min="0" max="500"/></label></p>

<p><label>Appointments: <input type="number" name="Appointments seen" min="0" max="7" /></label></p>

<p><label>Comments: <textarea name="Comments" rows="3" cols="40"></textarea></label></p>	

</fieldset>

<p align="center"><input type="submit" name="submit" value="Submit" /></p>
<?php $day = $_REQUEST['Date']; $clinic = $_REQUEST['Clinic']; $google = $_REQUEST['Claimed Mileage']; $actual = $_REQUEST['Actual Mileage']; $num_apps = $_REQUEST['Appointments seen']; $comments = $REQUEST['Comments']; $bonus = 0; $diff = $actual - $google; //Conditional Statements if (num_apps == 5){ $bonus = 20; } elseif (num_apps == 6){ $bonus = 60; } elseif (num_apps == 7){ $bonus = 100; }else{ $bonus = NULL; } if (isset($_REQUEST['Date'])) { $day = $_REQUEST['Date']; } else { $day = NULL; } if (isset($_REQUEST['Clinic'])) { $clinic = $_REQUEST['Clinic']; } else { $clinic = NULL; } if (isset($_REQUEST['Claimed Mileage'])) { $google = $_REQUEST['Claimed Mileage']; } else { $google = NULL; } if (isset($_REQUEST['Actual Mileage'])) { $actual = $_REQUEST['Actual Mileage']; } else { $actual = NULL; } if (isset($_REQUEST['Appointments seen'])) { $num_apps = $_REQUEST['Appointments seen']; } else { $num_apps = NULL; } if(isset($_POST['submit'])) { echo "Date: $day
Clinic: $clinic
Claimed Mileage: $google
Actual Mileage: $actual
Mileage Difference: $diff
Bonus today: $bonus"; } ?> [/code] Any help greatly appreciated!

Normally, for the programming variables do not contain capitals nor spaces. This causes a lot of problems in the
long run when using PHP. Therefore, change “Claimed Mileage” to just “claimed_mileage” or even better just
“mileage”. Underscores are allowed if you need to insert a space. Remember, websites are text files. And, that
means that that the smaller your text, the smaller the page and the faster it will load. Normally, you would want
to create a name for your variables is the smallest that makes sense as to it’s content.

Try removing the spaces and see if that works…

Oh, also, you can not display null’s. You might want to make the default for your variables either “” or zero
depending on text or numeric. Then, you can display them. If you store null’s, you need to do extra checks
to see if data exists in them. Of course, normally you validate the inputs to make sure they are legal for your
uses before doing anything with the data.

Thanks Ernie Alex for your reply. I changed the variables to small case and also the names in the form fields which I didn’t realise couldn’t contain spaces and it’s working great now thank you. :smiley:

If it helps anyone doing something similar here is the now working code:

[code]

Simple HTML Form label { font-weight: bold; color: #300ACC; } Please enter information in the form below:
<p><label>Date: <input type="date" name="date"/></label></p>

<p><label>Clinic: <input type="text" name="clinic" size ="20" maxlength="30"/></label></p>

<p><label>Google Miles: <input type="number" name="c_mileage" min="0" max="500"/></label></p>

<p><label>Actual Miles: <input type="number" name="a_mileage" min="0" max="500"/></label></p>

<p><label>Appointments: <input type="number" name="appointments" min="0" max="7" /></label></p>

<p><label>Comments: <textarea name="comments" rows="3" cols="40"></textarea></label></p>	

</fieldset>

<p align="center"><input type="submit" name="submit" value="Submit" /></p>
<?php $day = $_REQUEST['date']; $clinic = $_REQUEST['clinic']; $google = $_REQUEST['c_mileage']; $actual = $_REQUEST['a_mileage']; $num_apps = $_REQUEST['appointments']; $comments = $REQUEST['comments']; $bonus = 0; $diff = $actual - $google; //Conditional Statements if (num_apps == 5){ $bonus = 20; } elseif (num_apps == 6){ $bonus = 60; } elseif (num_apps == 7){ $bonus = 100; }else{ $bonus = 0; } if (isset($_REQUEST['date'])) { $day = $_REQUEST['date']; } else { $day = NULL; } if (isset($_REQUEST['clinic'])) { $clinic = $_REQUEST['clinic']; } else { $clinic = NULL; } if (isset($_REQUEST['c_mileage'])) { $google = $_REQUEST['c_mileage']; } else { $google = NULL; } if (isset($_REQUEST['a_mileage'])) { $actual = $_REQUEST['a_mileage']; } else { $actual = NULL; } if (isset($_REQUEST['appointments'])) { $num_apps = $_REQUEST['appointments']; } else { $num_apps = NULL; } if(isset($_POST['submit'])) { echo "Date: $day
Clinic: $clinic
Claimed Mileage: $google
Actual Mileage: $actual
Mileage Difference: $diff
Bonus today: $bonus"; } ?> [/code]

Glad you solved it. It is often a simple error. Quite often I forget one period, comma or semi-colon. Naming
conventions are very personal to some programmers. Some use capitals like “ErnieAlex”, some “erniealex”
and some “ernie_alex”… All work because no spaces. So, it’s up to you which is best and easiest for you to
read.

We will mark this one solved. Post a new one when you hit another snag…

Sponsor our Newsletter | Privacy Policy | Terms of Service