I'm trying to make a simple order form that will generate a mail with all the information and send it to a specific adress.
Here's what I wan't it to look like:
[IMG]http://filesmelt.com/dl/fitta.jpg[/IMG]
Is there anyone who can help me with this? I have limited knowledge of PHP/MySQL
Use POST to get what is entered into the boxes and use the mail() function.
[editline]26th October 2011[/editline]
If you can't do it yourself just read through this.
[url]http://www.phpjabbers.com/make-contact-form-and-send-email-in-php-php21.html[/url]
If you're inserting the information into a database (which I presume you are) then make sure you protect against SQL injection.
I'm no expert or anything, but I've come up with the below and believe it's sufficient, do correct me if I've made any mistakes.
[php]
<?php
mysql_connect("host", "username", "password"); // Connecting to the database server and selecting working database
mysql_selectdb("database_name") || die(mysql_error());
if(isset($_POST['send'])) // If user has submitted form, checks specifically if they have pressed the submit button
{
if(!$_POST['f_name'] || !$_POST['s_name'] || !$_POST['nr'] || !$_POST['color'] || !$_POST['quanitity']) // If user failed to fill out all the fields...
{
echo "You failed to fill out all of the required fields"; // Show error message
}
else // Otherwise if everything's OK...
{
// Below we're assigning variables to escape any characters inputted by the user in the fields, this is basic SQL injection prevention
$f_name = mysql_real_escape_string($_POST['f_name']);
$s_name = mysql_real_escape_string($_POST['s_name']);
$nr = mysql_real_escape_string($_POST['nr']);
$color = mysql_real_escape_string($_POST['color']);
$quantity = mysql_real_escape_string($_POST['quantity']);
mysql_query("INSERT INTO table_name VALUES({$f_name}, {$s_name}, {$nr}, {$color}, {$quantity})"); // Now we insert the escaped data into the database
// Mail() function to send an email can go here.
echo "Your order has been submitted, thank you"; // And supply a confirmation message to the user
}
}
else // If the user did NOT send the form yet...
{
?>
<!-- Below is the order form !-->
<form action="" method="POST" name="form">
First name <br />
<input type="text" name="f_name" />
<br /><br />
Surname <br />
<input type="text" name="s_name" />
<br /><br />
Nr (YYMMDD-XXXX) <br />
<input type="text" name="nr" />
<br /><br />
Color <br />
<select name="color">
<option value="red">Red</option>
<option value="another_colour">Another colour</option>
</select>
<br /><br />
Quantitiy: <br />
<input type="text" name="quantity">
<br /><br />
<input type="submit" name="send" value="Submit">
</form>
<?php
}
?>
[/php]
The above is assuming you have the tables in your databse setup (forename, surname, nr, color, quantity)
He doesn't want it to insert into a DB.
[QUOTE=wilki;33008089]He doesn't want it to insert into a DB.[/QUOTE]
[QUOTE=Nawl;32976747]I have limited knowledge of PHP/MySQL [/quote]
Maybe he got mixed up but nothing in his post does he say about inserting it into a database.
[QUOTE=wilki;33008255]Maybe he got mixed up but nothing in his post does he say about inserting it into a database.[/QUOTE]
He's not asking for it but it's implied that he'd prefer it.
I'm not too sure how this code works... hrm, can anyone help?
sorry to derail, but check out this image of beavis and buttehad having sex
[IMG]http://getcartoonsex.com/wp-content/uploads/2009/02/01.jpg[/IMG]
[QUOTE=Hizan;32992412]If you're inserting the information into a database (which I presume you are) then make sure you protect against SQL injection.
I'm no expert or anything, but I've come up with the below and believe it's sufficient, do correct me if I've made any mistakes.
[php]code
[/php]
The above is assuming you have the tables in your databse setup (forename, surname, nr, color, quantity)[/QUOTE]I got a syntax error when I tried this code? Any help?
[QUOTE=rickperryfan148;33016402]sorry to derail, but check out this image of beavis and buttehad having sex
[IMG]http://getcartoonsex.com/wp-content/uploads/2009/02/01.jpg[/IMG][/QUOTE]
DUDE. WHAT THE HELL.
[QUOTE=rickperryfan148;33016402]sorry to derail, but check out this image of beavis and buttehad having sex
[IMG]http://getcartoonsex.com/wp-content/uploads/2009/02/01.jpg[/IMG][/QUOTE]WHAT THE FUCK DUDE