2 problems, help is needed

Joined
12 Feb 2006
Posts
17,427
Location
Surrey
firstly i need help with the php form i have set up. i thought it was going to work but it appears not

here is the html code:
<form method="post" action="contact.php" >

<table>

<tr>
<td><p><b>Name :</b></p></td>
</tr>

<tr>
<td><input type="text" name="name" style="width:300px"/></td>
</tr>

<tr>
<td><p><b>Email Address :</b></p></td>
</tr>

<tr>
<td><input type="text" name="email" style="width:300px"/></td>
</tr>

<tr>
<td><p><b>Phone :</b></p></td>
</tr>

<tr>
<td><input type="text" name="phone" style="width:300px"/></td>
</tr>

<tr>
<td valign="top"><p><b>Enquiry :</b></p></td>
</tr>

<tr>
<td><textarea name="enquiry" style="width:300px" rows="5" cols="20"></textarea></td>
</tr>

<tr>
<td align="left"><p><b>Prefered method of contact:</b></p></td>
</tr>

<tr>
<td>
<input type="checkbox" name="contact" value="phone"/>
Telephone&nbsp;
<input type="checkbox" name="contact" value="email"/>
Email
</td>
</tr>

<tr>
<td colspan="2" align="center"><input type="submit" value="Submit"/></td>
</tr>

</table>
</form>

and the php file:
<html>
<body text="#000000" leftmargin="150" topmargin="20">

<?php
$emailadd = "[email protected]";


/*Edit the text below ( beginning with <div> and ending with </div> ) to the message of your choice
*/
$successmsg = <<<EOD

<div align = 'center'><p><br>
<h2>The Message was sent</h2><br>
<h3>We will contact you soon</h3><br>
<h3><a href="index.html">HOME</a></h3>
</p>
</div>

EOD;
?>

</body>
</html>

it doesn't work and how no idea why. This is my first php


ok now secondly trying get a photogallery to have thumbnails on the right and when you hover over them they load the image bigger with some text on the left. I have nearly completed it, the only problem im having is the images don't load in the correct place.

here is the site: http://ride.0taxi.com/addy010/art2.html (if you change page you wont be able to go back to that art page as isn't number 2)

anyone with any knowldge on how i'd sort this out?

[EDIT]
forgot to say that the following link is where the code came from, and i have altered it to fit mine, though not much, yet mine doesn't work.

http://www.webreference.com/programming/css_gallery/index.html
 
Last edited:
Looks like you've only got half the file or something, because it looks like the config half (setting a couple of the variables it uses) - check a fresh download of the script you used :)
 
Question 1:
All that PHP you've written does is assign two strings to two variables - if you want to print to the screen then you need to print those variables using echo or another print method, and if you want to actually send an email, then you need to use the mail() function.

There are plenty of form handling tutorials on the net for this kind of thing.

Your php file needs to do the following:
1. Capture and clense the form input
2. Create a message string with the relevant info from the form
3. Pass this message string, along with a subject and a to email address (and optionally a from email address) to the mail() function.


Question 2:
Not really a fix but you could try the tres cool lightbox javascript
 
LazyManc said:
Question 1:
All that PHP you've written does is assign two strings to two variables - if you want to print to the screen then you need to print those variables using echo or another print method, and if you want to actually send an email, then you need to use the mail() function.

There are plenty of form handling tutorials on the net for this kind of thing.

Your php file needs to do the following:
1. Capture and clense the form input
2. Create a message string with the relevant info from the form
3. Pass this message string, along with a subject and a to email address (and optionally a from email address) to the mail() function.


Question 2:
Not really a fix but you could try the tres cool lightbox javascript

hey thanks, this has helped me understand now what i need to research.

i have decided to screw the orignal artwork photo gallery and go to the same one on the photos page but just change it to look differnt
 
ok i have studied a php tutorial a bit and tried writting a form, and guess what its doesn't work.

this is the code i have written minus stuff from above:
Code:
<?php
if (isset($_REQUEST['name']))
  {
  $name = $_REQUEST['name'] ; 
  $landline = $_REQUEST['landline'] ;
  $mobile = $_REQUEST['mobile'] ;
  $mobile = $_REQUEST['address'] ;
  $mobile = $_REQUEST['week'] ;
  $mobile = $_REQUEST['days'] ;
  $mobile = $_REQUEST['requirement'] ;
  $mobile = $_REQUEST['found'] ;
  mail( "[email protected]",
  $message, "From: $name" );
  echo "Thank you for using our mail form";
  }
else

  {
  echo "<form action="book.php" method="post" >
            
                <table width="565px" align="center" cellpadding="0" cellspacing="0"  class="txt" style="border: 0px">
                  
                  <tr>
                    <td  align="left" valign="middle"><p class="text7"> Your Name :</p></td>
                    <td width="67%"><input type="text" name="name" size="30" width="300"/></td>
                  </tr>
                  
                  <tr>
                    <td  align="left" valign="middle" height="10"></td>
                  </tr>
                  
                  <tr height="42">
                    <td align="left" valign="middle"  height="42"><p class="text7"> Land Line Number :</p></td>
                    <td><input type="text" name="landline" size="30" width="300"/>

                    </td>
                  </tr>
                  <tr>
                    <td  align="left" valign="middle" height="10"></td>
                  </tr>
                  <tr>
                    <td align="left" valign="middle" ><p class="text7"> Mobile Number :</p></td>
                    <td><input type="text" name="mobile" size="30" border="0" width="300"/>

                    </td>
                  </tr>
                  <tr>
                    <td  align="left" valign="middle" height="10"></td>
                  </tr>
                  <tr>
                    <td align="left" valign="top" ><p class="text7"> Address :</p></td>
                    <td><textarea name="address" cols="23" rows="2" style="width:300px"></textarea></td>

                  </tr>
                  <tr>
                    <td  align="left" valign="middle" height="10"></td>
                  </tr>
                                    <tr>
                    <td  align="left" valign="middle" height="10"></td>
                  </tr>
                  <tr valign="top">
                    <td align="left" ><p class="text7"> Your Preferred Day :</p></td>
                    <td><p class="text1">
                        <input type="checkbox" name="week[]" value="Once a week"/>

                Once a week&nbsp;
                <input type="checkbox" name="week[]" value="2 Days a week"/>
                2 Days a week&nbsp;
                <input type="checkbox" name="week[]" value="Fortnightly"/>
                Fortnightly</p></td>
                  </tr>
                  <tr>

                    <td  align="left" valign="middle" height="2"></td>
                  </tr>
                  <tr valign="top">
                    <td align="left" ></td>
                    <td align="left" ><p align="center" class="text7">OR</p></td>
                  </tr>
                  <tr valign="top">
                    <td align="left" ></td>

                    <td align="left" ><p class="text1">
                        <input type="checkbox" name="days[]" value="Monday"/>
                Monday&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <input type="checkbox" name="days[]" value="Tuesday"/>
                Tuesday&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <input type="checkbox" name="days[]" value="Wednesday"/>
                Wednesday<br />

                <input type="checkbox" name="days[]" value="Thursday"/>
                Thursday&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
                <input type="checkbox" name="days[]" value="Friday"/>
                Friday &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <input type="checkbox" name="days[]" value="Saturday"/>
                Saturday<br />
                <input type="checkbox" name="days[]" value="Sunday"/>

                Sunday</p></td>
                  </tr>
                  <tr>
                    <td  align="left" valign="middle" height="10"></td>
                  </tr>
                  <tr>
                    <td align="left" valign="top"><p  class="text7"> Do you have any special requirements?</p></td>
                    <td valign="top"><textarea name="requirement" cols="23" rows="2" style="width:300px"></textarea></td>

                  </tr>
                  <tr>
                    <td  align="left" valign="middle" height="10"></td>
                  </tr>
                  <tr>
                    <td align="left" valign="top" ><p class="text7"> Please state how you found us:</p></td>
                    <td valign="top"><input type="text" name="found" size="30" border="0" width="300"/></td>
                  </tr>

                  <tr>
                    <td height="10" align="center" valign="middle" ></td>
                    <td></td>
                  </tr>
                  <tr>
                    <td align="center" valign="middle" ><input type="submit" value="Submit"/></td>
                    <td align="center"><input type="reset" name="Reset" value="Reset"/>
                    </td>
                  </tr>

                  <tr>
                    <td  align="center" valign="middle" height="10"></td>
                  </tr>
                </table>
            </form>";
  }
?>

</div>

<div id="footer"><p>Copyright &copy; 2006 Aloha Cleaning Services All Rights Reserved</p></div>

</div>
</body>
</html>

something i know so far that is wrong is that after the php is finished (?>)

it still hasn't counted as finished as the div, body, html are all green, and on the website is writes out ";}?>

Anyone know why?

Also noticed that the colour coding in notepad2 is wrong, once the <form> starts, which again i have no idea to why its doing that?

and the final problem so far is that when i try and click to the book.php page, which is where this code comes from, it just displays a download box (using FF2.0) and asks how to open the file. Why is it doing this? this is when looking at it from my computer, and not from the website

hope someone can shed some light on this, thanks
 
Last edited:
You've set $mobile to a million values, each of which overrides the last - just edit the variables, looks like you forgot to change the variable names after a copy/paste or something :)

The mail() won't do much because $message doesn't exist. Also, the parameters are of the type:

Code:
mail($to, $subject, $message, $headers);
Your first bit - the address - is fine, but you're missing a subject - you have the message in the subject section, and the from in the message section.

The funny 3 characters are here:

Code:
</form>";
}
?>

</div>

<div id="footer"><p>Copyright &copy; 2006 Aloha Cleaning Services All Rights Reserved</p></div>
:)
 
Beansprout said:
The mail() won't do much because $message doesn't exist. Also, the parameters are of the type:

Code:
mail($to, $subject, $message, $headers);
Your first bit - the address - is fine, but you're missing a subject - you have the message in the subject section, and the from in the message section.

The funny 3 characters are here:


ok i've changed the $mobile, thanks for pointing that out, sillyily forogt to change after a copy and paste, i shouldn't thave been lazy.

i'm trying to fix the mail but having difficulty. So your saying for the mail to work it needs a to, subject, message, headers (which are what)?

if so what is the message part, is that the form? how would i make the form go in the message part?

is it possible for the subject to just have it echo a subject saying online form. e.g.

Code:
"Subject: echo Online Form",

obviosuly not written right but you get the idea of what i mean

any light on why when viewing the site on my pc it tries to get me to open or save the book.php file and not just view it?
 
Last edited:
You need to compile $message from the other variables you created. Should be pretty straightforward, ie:

Code:
$message = "New message from $name, $address. Please call on $landline";
For mail():

Code:
mail( "[email protected]",  ""Subject: Online Form", $message);

You can't use the last parameter (extra headers) because they're there to specify the sender - which isn't a name - it's an e-mail address (but you can add a name as that's what you see when you look in your inbox and see who an e-mail is from):

Code:
$headers .= 'From: Someone <[email protected]>';
So, if you grabbed an e-mail address through the form then you could use that - otherwise I'd just leave it to be honest, and accept whatever your host sets as the default sender - ie, don't worry about advanced things until the basic part works :)

I think this is all correct....I'm kinda speed-typing :)
 
thanks for the speedy relpy, i tihnk i have sorted the email bit out now but there is still more problems as the form isn't working properly,

here is the updated code
Code:
<?php
if (isset($_REQUEST['name']))
  {
  $name = $_REQUEST['name'] ; 
  $landline = $_REQUEST['landline'] ;
  $mobile = $_REQUEST['mobile'] ;
  $address = $_REQUEST['address'] ;
  $week = $_REQUEST['week'] ;
  $days = $_REQUEST['days'] ;
  $requirements = $_REQUEST['requirement'] ;
  $found = $_REQUEST['found'] ;
  $message = "New message from $name, $address. Please call on $landline or $mobile, how often is $week, day wanted is $days. the special requirements are: $requirement, the found us by $found";
   
  mail( "[email protected]",  ""Subject: Online Form", $message);
  
	echo "Thank you for using our mail form";
  }
else

  {
  echo "<form action="book.php" method="post" >
			
				<table width="565px" align="center" cellpadding="0" cellspacing="0"  class="txt" style="border: 0px">
				  
				  <tr>
					<td  align="left" valign="middle"><p class="text7"> Your Name :</p></td>
					<td width="67%"><input type="text" name="name" size="30" width="300"/></td>
				  </tr>
				  
				  <tr>
					<td  align="left" valign="middle" height="10"></td>
				  </tr>
				  
				  <tr height="42">
					<td align="left" valign="middle"  height="42"><p class="text7"> Land Line Number :</p></td>
					<td><input type="text" name="landline" size="30" width="300"/>

					</td>
				  </tr>
				  <tr>
					<td  align="left" valign="middle" height="10"></td>
				  </tr>
				  <tr>
					<td align="left" valign="middle" ><p class="text7"> Mobile Number :</p></td>
					<td><input type="text" name="mobile" size="30" border="0" width="300"/>

					</td>
				  </tr>
				  <tr>
					<td  align="left" valign="middle" height="10"></td>
				  </tr>
				  <tr>
					<td align="left" valign="top" ><p class="text7"> Address :</p></td>
					<td><textarea name="address" cols="23" rows="2" style="width:300px"></textarea></td>

				  </tr>
				  <tr>
					<td  align="left" valign="middle" height="10"></td>
				  </tr>
									<tr>
					<td  align="left" valign="middle" height="10"></td>
				  </tr>
				  <tr valign="top">
					<td align="left" ><p class="text7"> Your Preferred Day :</p></td>
					<td><p class="text1">
						<input type="checkbox" name="week[]" value="Once a week"/>

				Once a week&nbsp;
				<input type="checkbox" name="week[]" value="2 Days a week"/>
				2 Days a week&nbsp;
				<input type="checkbox" name="week[]" value="Fortnightly"/>
				Fortnightly</p></td>
				  </tr>
				  <tr>

					<td  align="left" valign="middle" height="2"></td>
				  </tr>
				  <tr valign="top">
					<td align="left" ></td>
					<td align="left" ><p align="center" class="text7">OR</p></td>
				  </tr>
				  <tr valign="top">
					<td align="left" ></td>

					<td align="left" ><p class="text1">
						<input type="checkbox" name="days[]" value="Monday"/>
				Monday&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<input type="checkbox" name="days[]" value="Tuesday"/>
				Tuesday&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<input type="checkbox" name="days[]" value="Wednesday"/>
				Wednesday<br />

				<input type="checkbox" name="days[]" value="Thursday"/>
				Thursday&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
				<input type="checkbox" name="days[]" value="Friday"/>
				Friday &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<input type="checkbox" name="days[]" value="Saturday"/>
				Saturday<br />
				<input type="checkbox" name="days[]" value="Sunday"/>

				Sunday</p></td>
				  </tr>
				  <tr>
					<td  align="left" valign="middle" height="10"></td>
				  </tr>
				  <tr>
					<td align="left" valign="top"><p  class="text7"> Do you have any special requirements?</p></td>
					<td valign="top"><textarea name="requirement" cols="23" rows="2" style="width:300px"></textarea></td>

				  </tr>
				  <tr>
					<td  align="left" valign="middle" height="10"></td>
				  </tr>
				  <tr>
					<td align="left" valign="top" ><p class="text7"> Please state how you found us:</p></td>
					<td valign="top"><input type="text" name="found" size="30" border="0" width="300"/></td>
				  </tr>

				  <tr>
					<td height="10" align="center" valign="middle" ></td>
					<td></td>
				  </tr>
				  <tr>
					<td align="center" valign="middle" ><input type="submit" value="Submit"/></td>
					<td align="center"><input type="reset" name="Reset" value="Reset"/>
					</td>
				  </tr>

				  <tr>
					<td  align="center" valign="middle" height="10"></td>
				  </tr>
				</table>
			</form>";
  }
?>

the colour is still wrong. When viewing it online this is what i get: http://www.alohaclean.co.uk/book.php

i know that the problem starts where the <form> starts but i have no clue as to why. the colour coding from notepad2 goes all wrong, like the <div id> usually has a red id part, but now its all just green, the php colouring. anything above the php is still all coloured right though.

Also any light on why when viewing the website from the pc it asks me to download the php file? rather then just show it?
 
Eek - you don't need to echo all that HTML (it'd be a nightmare to setup properly). Just close the PHP tag and re-open it after the HTML, ie:

Code:
else

  {
?>
....HTML....
<? }...etc ?>

Also, your PC doesn't have a PHP interpreter (ie webserver) so it can't execute it - as far as it knows, it's just a text file :)
 
ok i think its coming almost to completion now.

the reason for the colour change i think may have been because in the below code, just before subject i had 2 quotation marks like so "", when i changed it it all went fine. Still though when triyng to view that page there is a problem with the mail part

this what i got
Code:
  mail( "[email protected]","Subject: Online Form"
  $message );

anthing that could be wrong with that?
 
:) it work, it works, it works! im so happy finally got my first bit of php to work. just like to take a moment to say thanks to beanspout, i wouldn't have managed it without you, i really appreciate it
 
ok i have just realised i still have a problem with the form on my site. when someone fills out the form it gets sent all fine and the fields are all sent, except 2 which have 3/7 checkboxes and no matter what is selected will email me saying Array.

how can i get it to say the name of the field.

this is the code for the checkboxes part of the form:

Code:
<tr valign="top">
					<td align="left" ><p class="text7"> Your Preferred Day :</p></td>
					<td><p class="text1">
						<input type="checkbox" name="week[]" value="Once a week"/>

				Once a week&nbsp;
				<input type="checkbox" name="week[]" value="2 Days a week"/>
				2 Days a week&nbsp;
				<input type="checkbox" name="week[]" value="Fortnightly"/>
				Fortnightly</p></td>
				  </tr>
				  <tr>

					<td  align="left" valign="middle" height="2"></td>
				  </tr>
				  <tr valign="top">
					<td align="left" ></td>
					<td align="left" ><p align="center" class="text7">OR</p></td>
				  </tr>
				  <tr valign="top">
					<td align="left" ></td>

					<td align="left" ><p class="text1">
						<input type="checkbox" name="days[]" value="Monday"/>
				Monday&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<input type="checkbox" name="days[]" value="Tuesday"/>
				Tuesday&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<input type="checkbox" name="days[]" value="Wednesday"/>
				Wednesday<br />

				<input type="checkbox" name="days[]" value="Thursday"/>
				Thursday&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
				<input type="checkbox" name="days[]" value="Friday"/>
				Friday &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<input type="checkbox" name="days[]" value="Saturday"/>
				Saturday<br />
				<input type="checkbox" name="days[]" value="Sunday"/>

				Sunday</p></td>
				  </tr>
				  <tr>
					<td  align="left" valign="middle" height="10"></td>
				  </tr>

also something else that would be fly is that at the moment when a message is sent some text comes up on the current page saying something like "the message has been sent blah blah blah", i'm wondering how i can make it, either show the text in bold so people see it more, or make it load another simply page saying message sent etc for like 5 seconds then go back to the home page or some other page.

thanks all
 
The checkboxes are returned as an array (days) because multiple values can be selected. If you try to use echo on an array, it will just print the word array - you need to either loop through the array and print one at a time (see foreach), or turn the array into a string (implode) and print that.

If you just want to be able to select one day at a time, use radio buttons and then the form will only return a string.
 
Back
Top Bottom