PHP newbie help

Joined
12 Feb 2006
Posts
17,427
Location
Surrey
well have read an online tutorial to teach me a quick rough guide to php as i have nearly finished my website and a small amount of php what i need to know. though it is only a small amount of php i need this is not easy and i'm having to turn to ocuk for the help for now until i get mroe time next week to learn php

what im hoping is if someone could bascially just fill me in on what i need to be putting, or atleast a rough guide on what needs to be done.

So far i have a contact page and a book online page on my website, which are bascially the same thing except slightly different questions are asked, they both have around 6 questions, like name, email, telephone, enquiry etc.

this is the html i got for the contact page form:

<form name="contactform" method="post" action="contact.php" >

<tr>
<td width="38%" valign="top" class="text7"><p><b>Name :</b></p></td>
<td width="62%" valign="top" bgcolor="#FFFFFF"><input type="text" name="name" style="width:300px"></td>
</tr>
<tr>
<td valign="top" class="text7"><p><b>Email Address :</b></p></td>
<td valign="top" bgcolor="#FFFFFF"><input type="text" name="email" style="width:300px"></td>
</tr>

<tr>
<td valign="top" class="text7"><p><b>Phone :</b></p></td>
<td valign="top" bgcolor="#FFFFFF"><input type="text" name="phone" style="width:300px"></td>
</tr>
<tr>
<td valign="top" class="text7"><p><b>Enquiry :</b></p></td>
<td valign="top" bgcolor="#FFFFFF"><textarea name="enquiry" style="width:300px" rows="5" cols="20"></textarea></td>

</tr>
<tr>
<td align="left" valign="top" ><p class="text7"><b>Prefered method of contact:</b></p></td>
<td>
<input type="checkbox" name="contact" value="phone">
Telephone&nbsp;
<input type="checkbox" name="contact" value="email">
Email</p></td>
</td>

</tr>
<br>
<br>
<tr>
<td colspan="2" bgcolor="#FFFFFF" align="center"><input type="submit" name="submit_contact" value="Submit" onClick="javascript:return check2();"></td>
</tr>
</form>

this im hoping would send the info to a php file called contact?

and on that page i have only

<html>
<body>

Name: <?php echo $_POST["name"]; ?>.<br />
Email Address: <?php echo $_POST["email"]; ?>.
Phone: <?php echo $_POST["phone"]; ?>.
Enquiry: <?php echo $_POST["enquiry"]; ?>.
Prefered Method of Conact: <?php echo $_POST["contact"]; ?>.


</body>
</html>

i know what i have done must be compltelty wrong which is why im here for the help now so i can get this site up and running tonight, and then i learn php next week.

Only other thing im thinking i could do would just do a mailto instead which would make it much easier. the only reason im not is because i don't like how to submit a form you have to load up outlook express so if it was me i would just leave the form and not bother which im guessing customers would aswell, maybe not all the time but sometimes. am i wrong about this?

finally if not php is there another alternative that will bascially just save the form information onto a page that only i can get to and not the public that would be simple?
 
Last edited:
finally if not php is there another alternative that will bascially just save the form information onto a page that only i can get to and not the public that would be simple?

You could set it up so that your form will submit the information into a database, which you can browse through at your convenience (and it will be hidden from the public - provided you keep your passwords etc secure!). If you want to do this and not sure how.. then I could lend you a hand.
 
There are several possible alternatives:

  • Use the mail() function to have the results emailed to your email address once filled in.
  • Use a database table to store the results of the query.
  • Use a text file as a flat-file database, and write to it using fwrite() or similar. You'd have to CHMOD the file or appropriate to set the read/write permissions.

The former option will probably be the easiest to implement based on the fact that you're new to PHP, but it is understandable that you may not want to have the query sent to your email but rather displayed onscreen. If you decide to go down the second route, you'll have to learn the basics of a database language (I'd recommend SQLite over MySQL) and its integration with PHP. Personally, I would recommend this as it will also benefit you down the line when you inevitably explore database utilisation.
 
ok well i've decided to go with the mailto option, only thing now is that when the person clicks submit and it loads up there emails, the email isn't very readable in that it looks like this:

Name=hello&landline=0111124545&mobile=53456454&Address1=123+Fake+Street&week%5B%5D=Once+a+week&days%5B%5D=Tuesday&requierment=nope&found=google


Is there anyway i can make this a little nicer so that when it gets sent to me i can easily read it?





this isn't needed too much, but also is there anyway to make it so that once the email is sent it clears the form?
 
I agree, addy, it's much better to have the form submitted to a database which you can browse.
 
I'd still favour the database, as it will allow you to sort your data etc if you want to later.

Tell us what route you'd like to pursue and we can then help you further.
 
bascialy the best/easiest way for the customer to submit the forms, and then the best way for me to see the forms. If it looks ugly only for me its not a problem, but it its anoying for the customer obbviosuly thats not a good idea. I have no clue which is the best method for this, any as long as they give me what i want above
 
There's a difference between best and easiest. There's also a difference between using hideous HTML "mailto" forms and using server-side solutions, such as the PHP mail() function which I previously suggested. The easiest solution would be to use mailto or any revelant mail functions; the "best" solution to store the data in either a flat-file or relational database. In order to implement the latter, you will have to put the work in yourself and learn PHP properly as well as a database query language.

It's one thing asking for help with a specific line or section of code, but another thing entirely asking for exact instructions of how to do something. If you can't be bothered to put the effort in, or don't have the time, to learn programming languages; tutorials most likely exist to aid you with creating contact forms and the like. However, you should consider learning the fundamentals of PHP properly: either by investing in a book or by using the vast amount of online resources available. Otherwise, you run the risk of trying to guess how to perform certain operations and end up half-arsing everything.

My advice would be to learn PHP and a query language properly. Then, once you've attempted to solve a problem yourself having understood the basics of the language, I'd be happy to offer my assistance. Alternatively, free scripts and tutorials exist online relating to specific problems; Google them if necessary. Of course, without knowing the basics of PHP you run the risk of not been able to successfully modify and customise these scripts to suit your problem.

In terms of logic rather than the actual code, you'd be looking at something along the following lines:

  • mail() - Create post form, action set to $_SERVER['PHP_SELF']. Inputs for each specific field. Use the mail() function, ensuring incoming data is properly sanitised, to send the email to your own address, ensuring carriage returns separate each of the datum in the email body. Or the database...
  • Database - Table created name "queries" or similar with appropriate fields set. Take the contents of the input data and insert them into the appropriate fields in the database when submitted. Then, create a page which uses a looped query to output the fields into a table or whatever form you'd like the information to take. You would use htaccess/htpasswd or a PHP security method to ensure that only you can access that page.
 
Last edited:
Back
Top Bottom