Quote:
Originally Posted by cd34
I usually prefer to use $_REQUEST['fieldname']
|
Cool, I never tried that, sounds like using $_REQUEST will make life a lot easier. |cool|
Ponyman, here's an example code you can test. If you want more info, just look it up at
PHP.net (I'm sure you already know that url though).
form.html:
HTML Code:
<form method="post" action="eatthis.php">
Your Nick:
<input name="name" type="text"><BR>
Email Addres:
<input name="email" type="text"><BR>
Subject:
<input name="subject" type="text">
Message:<textarea name="message" cols="50" rows="17">
<input name="Submit" type="submit" value="Send it baby!">
</form>
eatthis.php
PHP Code:
<?php
// Capture info sent from the form in variables
$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$subject = $_REQUEST['subject'];
$message = $_REQUEST['message'];
// Print out one of the vars on the page just to make sure you got it
echo "Who the hell sent me this MESSAGE?? $message<BR>";
// Email it to myself
mail('admin@YOUREMAILADDY.com', $subject, $message, "From: $name ($email)\r\n");
// Enter it in a database... Here you need to have a MYSQL table set up, lets call it EMAIL, with fields email,subject, message
// hook up to MYSQL
$link = mysql_connect('localhost', 'YOURUSERNAME', 'PASSWORD') or die('Failed to connect to SQL server.\n');
mysql_select_db('TABLENAME') or die('Failed to connect to the database.\n');
//enter info into DB. Note: there may be cleaner ways of entering strings into DB, but this works for me. Also note that how you order the values depends on how you built your MYSQL table, so you'll prolly need to play around a bit before you get it to work.
$query = "INSERT INTO email (name,email,subject,message) VALUES \"$name\",\"$email\",\"$subject\",\"$message\")";
// that's the query string. Just send it to MYSQL and you're done:
mysql_query($query);
// If you want error reporting, use: mysql_query($query) or mysql_error();
// You can also write your own function for error reporting. If you want to make sure you disconnect from MYSQL after you're done, use: mysql_close($link);
?>