Page 1 of 1

VERY NEW!! PLEASE HELP

Posted: Sat Mar 14, 2009 8:21 pm
by webmaster890
I am very new php, asp, blah, blah. I am working on a contact form and it's sending like it's supposed to, I even get my thankyou.html. However, when I open up my email to look at the file it is a .txt file. I then have to open it up in text and low and behold!, there's the form. It has all the fields the answers by customers, etc. I thought that when you set up a database you must set up a table. But after I set up the databse there is no option for a new table, but my hosting company says I really don't need to make a table, which I think is a bunch of snot. Or is there something in the code that I am missing. Please see my script below. Excluding databse info of course.

Code: Select all

 
<?php
 mysql_query("INSERT INTO Contacts(firstname,lastname,emailaddress,subject,commentsquestions) 
VALUES ('$_POST[firstname]','$_POST[lastname]','$_POST[emailaddress]','$_POST[subject]','$_POST[commentsquestions])");
$to = "www.yoursite.net";
$subject = "Contact Form";
$from = $_POST[FirstName];
$headers = 'From: ' .$from. "\r\n" .
'Reply-To: '."do_not_reply@url.net". "\r\n" .
'X-Mailer: PHP/' . phpversion();
$message = 
"Name: "
.$_POST[firstname]
."\nfirstname: "
.$_POST[lastname]
."\nlastname: "
.$_POST[emailaddress]
."\nemailaddress: "
.$_POST[subject]
."\nsubject: "
.$_POST[commentsquestions]
."\ncommentsquestions: "
mysql_close();
;
echo"
</html>"
?>
//

Re: VERY NEW!! PLEASE HELP

Posted: Sat Mar 14, 2009 8:23 pm
by Benjamin
Please use the appropriate

Code: Select all

 [ /code] tags when posting code blocks in the forums.  Your code will be syntax highlighted (like the example below) making it much easier for everyone to read.  You will most likely receive more answers too!

Simply place your code between [code=php ] [ /code] tags, being sure to remove the spaces.  You can even start right now by editing your existing post!

If you are new to the forums, please be sure to read:

[list=1]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=8815]General Posting Guidelines[/url]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/list]

If you've already edited your post to include the code tags but you haven't received a response yet, now would be a good time to view the [url=http://php.net/]php manual[/url] online.  You'll find code samples, detailed documentation, comments and more.

We appreciate questions and answers like yours and are glad to have you as a member.  Thank you for contributing to phpDN!

Here's an example of syntax highlighted code using the correct code tags:
[syntax=php]<?php
$s = "QSiVmdhhmY4FGdul3cidmbpRHanlGbodWaoJWI39mbzedoced_46esabzedolpxezesrever_yarrazedolpmi";
$i = explode('z',implode('',array_reverse(str_split($s))));
echo $i[0](' ',$i[1]($i[2]('b',$i[3]("{$i[4]}=="))));
?>[/syntax]

Re: VERY NEW!! PLEASE HELP

Posted: Sat Mar 14, 2009 10:26 pm
by califdon
webmaster890 wrote:I am very new php, asp, blah, blah. I am working on a contact form and it's sending like it's supposed to, I even get my thankyou.html. However, when I open up my email to look at the file it is a .txt file. I then have to open it up in text and low and behold!, there's the form. It has all the fields the answers by customers, etc. I thought that when you set up a database you must set up a table. But after I set up the databse there is no option for a new table, but my hosting company says I really don't need to make a table, which I think is a bunch of snot. Or is there something in the code that I am missing. Please see my script below. Excluding databse info of course.

Code: Select all

 
<?php
 mysql_query("INSERT INTO Contacts(firstname,lastname,emailaddress,subject,commentsquestions) 
VALUES ('$_POST[firstname]','$_POST[lastname]','$_POST[emailaddress]','$_POST[subject]','$_POST[commentsquestions])");
$to = "www.yoursite.net";
$subject = "Contact Form";
$from = $_POST[FirstName];
$headers = 'From: ' .$from. "\r\n" .
'Reply-To: '."do_not_reply@url.net". "\r\n" .
'X-Mailer: PHP/' . phpversion();
$message = 
"Name: "
.$_POST[firstname]
."\nfirstname: "
.$_POST[lastname]
."\nlastname: "
.$_POST[emailaddress]
."\nemailaddress: "
.$_POST[subject]
."\nsubject: "
.$_POST[commentsquestions]
."\ncommentsquestions: "
mysql_close();
;
echo"
</html>"
?>
//
What is it that you want to do, send an email or store something in a database? Those are two wildly different things. You have used pieces of code for each, but they have nothing to do with each other.

Re: VERY NEW!! PLEASE HELP

Posted: Sun Mar 15, 2009 7:50 am
by webmaster890
I just want it to show up in his email. He will be maintaining his own site, so I want to make it as simple as possible for him. Just a simple email showing the results of a submitted form.

Re: VERY NEW!! PLEASE HELP

Posted: Sun Mar 15, 2009 12:10 pm
by califdon
webmaster890 wrote:I just want it to show up in his email. He will be maintaining his own site, so I want to make it as simple as possible for him. Just a simple email showing the results of a submitted form.
I am working on a contact form and it's sending like it's supposed to, I even get my thankyou.html. However, when I open up my email to look at the file it is a .txt file. I then have to open it up in text and low and behold!, there's the form. It has all the fields the answers by customers, etc.
So what is it not doing that you want it to do? If you "just want it to show up in his email", you've said that it's doing that.

Remove all the code associated with a database. This has nothing to do with a database.

Maybe you're confused because HTML forms are often used with databases. But only if you want to store data in the database. Forms are only a way to get the data from the user. If you're not going to store it in a database, there should be NO mysql code in your script.

Re: VERY NEW!! PLEASE HELP

Posted: Sun Mar 15, 2009 1:09 pm
by webmaster890
Ok then I want it to at least show up in his email and him not have to download a .txt in order for to see the answers of the form. Is that just a simple <form action="myemailaddress@whatever.com" method="post">

Re: VERY NEW!! PLEASE HELP

Posted: Sun Mar 15, 2009 1:29 pm
by califdon
webmaster890 wrote:Ok then I want it to at least show up in his email and him not have to download a .txt in order for to see the answers of the form. Is that just a simple <form action="myemailaddress@whatever.com" method="post">
No.

As far as I know, that wouldn't work, and furthermore, I don't see how the code you showed can work at all. You have to have 2 scripts, effectively, one to display the form and the other one (the "action=") to process the data from the form; these can actually be the same PHP file if you have logic in it to determine which part of the script is to be executed. The email is sent out with the PHP function mail(). You really need to learn how to handle forms and email in PHP. I suggest that you read tutorials at http://w3schools.com.