Greenguy's Board

Greenguy's Board (http://www.greenguysboard.com/board/index.php)
-   Programming & Scripting (http://www.greenguysboard.com/board/forumdisplay.php?f=15)
-   -   Help with PHP submit form (http://www.greenguysboard.com/board/showthread.php?t=21922)

ponyman 2005-07-12 10:56 PM

Help with PHP submit form
 
I'd like to create a submit from for my LL using PHP.

Can anyone direct me to a tutorial on this?

Halfdeck 2005-07-12 11:51 PM

For forms, I usually create an HTML page with


Then write in file.php:


$useremail = $_GET['email'];
$title = $_GET['title'];
$description = ....

?>

Then either build an email message to myself or enter the info into a MYSQL DB (or both).

Let me know if you were looking for more detailed info |peace|

ponyman 2005-07-13 12:32 AM

I think that's what I need, but I'm way behind on this PHP stuff, so that still looks really confusing to me. I'm going to go do some research on this and I'll be back tomorrow, hopefully further along :)

I really appreciate the help!

cd34 2005-07-13 02:06 AM

I usually prefer to use $_REQUEST['fieldname'] -- that way you don't have to worry about whether it is method="GET" or method="POST" in your form. And I prefer to use POST rather than GET anyhow.

then, you can insert the records into your database, or create an email that is mailed to you.

Halfdeck 2005-07-13 10:28 AM

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">
Email Addres:
<input name="email" type="text">
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);

?>


ponyman 2005-07-26 04:37 PM

Yo halfdeck, I tried that out and I couldn't get it to work. I click on the submit button and it looks like it's working, but I get no e-mail at all.

I found this php form for e-mail, but it looks even more complicated: http://www.alt-php-faq.org/local/48/#id48

ponyman 2005-07-26 04:39 PM

hmmm. the form works if I don't fill it out and just click submit, I geta a blank e-mail

here is the .php file


// Capture info sent from the form in variables


$Title = $_REQUEST['Title:'];
$URL = $_REQUEST['URL:'];
$Category = $_REQUEST['Category'];
$Type = $_REQUEST['Type'];
$Comments = $_REQUEST['Comments'];
$nickname = $_REQUEST['nickname'];
$email = $_REQUEST['email'];


// Print out one of the vars on the page just to make sure you got it

echo "Thanks for submitting to The Sexwitch! You will receive an e-mail about your site once it has been reviewed. $message
";

// Email it to myself

mail('sexwitch@sexwitch.com', $Title, $URL, $Category, "From: $nickname ($email)\r\n");
?>

pornoTGB 2005-07-26 09:08 PM

$address = ''; //the address it will be sent to
$subject = ''; //the subject that will show up
$email = ''; //the email-text
$header = ''; //email-header

mail($address,$subject,$email,$header); //this line sends the mail


you used a wrong syntax in the mail-function
mail('sexwitch@sexwitch.com', $Title, $URL, $Category, "From: $nickname ($email)\r\n");
you can't just add your variables and seperate them with a ',' The function needs the correct syntax.. find more here: http://www.php.net/manual/en/function.mail.php
another mistake is "From: $nickname ($email)\r\n" .. this would put out exactly what you have .. rather try this: 'From: '.$nickname.'
Message: '.$email
what this does: it takes the text 'From: ' and adds the content of the variable $nick to it. then another text and the content of $email.. remember to add dots inbetween them

ponyman 2005-07-26 11:00 PM

This is what I've got so far


// Capture info sent from the form in variables


$Title = $_REQUEST['Title:'];
$URL = $_REQUEST['URL:'];
$Category = $_REQUEST['Category'];
$Type = $_REQUEST['Type'];
$Comments = $_REQUEST['Comments'];
$nickname = $_REQUEST['nickname'];
$email = $_REQUEST['email'];


// Print out one of the vars on the page just to make sure you got it

echo "Thanks for submitting to The Sexwitch! You will receive an e-mail about your site once it has been reviewed. $message
";

// The message
$message = "Line 1\nLine 2\nLine 3";

// Email it to myself
$message = "$Title\n$URL\n$Category";
$address = ' sexwitch@sexwitch.com';
$subject = 'Sexwitch Submit';
$email = ' blank';
$header = ' sexwitch@sexwitch.com';


mail($address,$subject,$email,$header,$message);
?>


It sends an e-mail with headers with the word "blank" in the body.

Now I can't figure how to add the captured text from the form into the email.

Halfdeck 2005-07-26 11:11 PM

Like PornoTGB pointed out, you have to stick to this basic syntax:

mail($targetemail, $subject, $message);

Example: mail("paulazahn@cnn.com","Re:Nice interview last night", "Hey Paula, just saw your interview with the girl working for New York Confidential....");

If you want to add header info, then like on the example on http://us2.php.net/manual/en/function.mail.php,
use: mail($targetemail, $subject, $message, $header).

In other words, mail($subject, $target_email, $header...) or any other variants like mail($header, $subject, $to_email) ... will not work.

ponyman 2005-07-27 12:18 AM

Ok, I think I finally got my SUBMIT FORM working. If anyone wants to submit some no recip required sites to help me further test the form, please go ahead, I'll list them.
http://www.sexwitch.com/webmasters.html

Doug E 2005-07-27 06:42 AM

i submitted and got this reply.

Quote:

SUCCESS! Thanks for submitting to The Sexwitch!
You will receive an e-mail about your site once it has been reviewed.

testest http://www.pornobobslinks.com/galler...chanapa03.html ETHNIC (Asians, Latina...) FREE just helping you test your form man, feel free to delete this gal. Doug E @ UncleWangs xxxxxxxxx@hotmail.com

ponyman 2005-07-27 06:13 PM

Thanks Doug E, People's submits seem to be working fine now. :)


All times are GMT -4. The time now is 07:07 AM.

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
© Greenguy Marketing Inc