email form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

byxbe
Forum Newbie
Posts: 8
Joined: Thu Aug 21, 2008 11:16 am

email form

Post by byxbe »

I am trying to create a form that will send information to me from my site. I am a beginner at php so bear with me.
On my site I have used a mySQL database to store usernames and passwords. I have set up a login application that remembers the user and I would like to incorporate it into the emailer so that when they submit the purchase order form they dont have to type in their name or information again.
this is the code that displays the username on each page "get_username ( $_SESSION['user_id'] )"

and this is my email form:
<?php
mail("name@domain.com","Purchase Order","username=".$_POST[$_SESSION['user_id']]."

\n10ct=".$_POST['10ct']."

\n30ct=".$_POST['30ct']."

\n50ct=".$_POST['50ct']."

\npromopack=".$_POST['promopack']."

\n","From:"."name@domain.com"); header ("location: http://www.mysite.com/");

?>

Is there any hope?
dajawu
Forum Commoner
Posts: 59
Joined: Fri May 23, 2008 10:16 am

Re: email form

Post by dajawu »

If you have the info stored in a session variable you can extract it using $_SESSION['uname'] , you only use $_POST['variable'] when its comming from a form with the action type POST, or $_GET['variable'] when your action is GET, or the variable is stored in the URL. If this doesn't help, please explain the problem your having with your code.
byxbe
Forum Newbie
Posts: 8
Joined: Thu Aug 21, 2008 11:16 am

Re: email form

Post by byxbe »

i used the $_SESSION['user_id'] and it pulled up the id field in the table which is 2. This made me think to change it to the field Username however the results in the email came up blank.
dajawu
Forum Commoner
Posts: 59
Joined: Fri May 23, 2008 10:16 am

Re: email form

Post by dajawu »

WHy above do you have $_POST[$_SESSION['user_id']] ? Session variables do not come from $_POST, if they are set properly you can call them up anytime with just $_SESSION['var'];
byxbe
Forum Newbie
Posts: 8
Joined: Thu Aug 21, 2008 11:16 am

Re: email form

Post by byxbe »

i have taken the $_POST off.. that was me in frustration trying anything possible. I have followed your instructions and have made it pull the value from the ID field in the table ['user_id'] however when i substitute that with ['username'] which is also a field in the table i do not get anything.
dajawu
Forum Commoner
Posts: 59
Joined: Fri May 23, 2008 10:16 am

Re: email form

Post by dajawu »

Ok but just because that is a field in your table, doesn't mean its set to a session variable. Show me your code, that pulls the DB info and stores it in variables.
byxbe
Forum Newbie
Posts: 8
Joined: Thu Aug 21, 2008 11:16 am

Re: email form

Post by byxbe »

<?php
echo 'Hello <strong>' . get_username ( $_SESSION['user_id'] )

this pulls the username and displays it on each page. i am using a tutorial and cant find where it is established as a variable. like i said I am a beginner with php but it pulls it and displays it on the page so it seems like it should be possible to put it in a emailer.
dajawu
Forum Commoner
Posts: 59
Joined: Fri May 23, 2008 10:16 am

Re: email form

Post by dajawu »

Try storing it in a variable first, such as:

$UN = get_username($_SESSION['user_id']);
echo $UN;

If that works, go ahead and keep the first line, and put the $UN variable in your mail code. Sorry for not understanding you eariler, this now makes a little more sence.

Al
byxbe
Forum Newbie
Posts: 8
Joined: Thu Aug 21, 2008 11:16 am

Re: email form

Post by byxbe »

i found this. Does this help at all? Where would i store the var statement that you made?

function get_username ( $id )
{
$query = mysql_query("SELECT `Username` FROM `users` WHERE `ID` = '" . mysql_real_escape_string ( $id ) . "'");

if ( mysql_num_rows ( $query ) == 1 )
{
$row = mysql_fetch_array ( $query );

return $row['Username'];
}
else {
return FALSE;
}
}
dajawu
Forum Commoner
Posts: 59
Joined: Fri May 23, 2008 10:16 am

Re: email form

Post by dajawu »

Put my code right above your SQL statement, then in your SQL use the variable instead of that $_POST[$_SESSION[]] stuff.
byxbe
Forum Newbie
Posts: 8
Joined: Thu Aug 21, 2008 11:16 am

Re: email form

Post by byxbe »

everything you are saying is making sense but for some reason i am having trouble following it.
this is my code for the emailer form. the least i can do is provide some humor for you.

<?php

require_once('db.php');
include('functions.php');
include('settings.php');
checkLogin('1 2');

$UN = get_username($_SESSION['user_id']);
echo $UN;

mail("stephen@stephenbyxbe.com","Wholesale Order","username=" ['UN']."

\n10ct=".$_POST['10ct']."

\n30ct=".$_POST['30ct']."

\n50ct=".$_POST['50ct']."

\npromopack=".$_POST['promopack']."

\n","From:"."info@stephenbyxbe.com"); header ("location: http://www.stephenbyxbe.com/thankyou.php");

?>
dajawu
Forum Commoner
Posts: 59
Joined: Fri May 23, 2008 10:16 am

Re: email form

Post by dajawu »

Thats not how you call up a variable that you've set. You need to call it up just like in the echo statement. Try this in your mail code:

Code: Select all

 
 
"username = $UN"
 
 
byxbe
Forum Newbie
Posts: 8
Joined: Thu Aug 21, 2008 11:16 am

Re: email form

Post by byxbe »

did not work..
dajawu
Forum Commoner
Posts: 59
Joined: Fri May 23, 2008 10:16 am

Re: email form

Post by dajawu »

code?
byxbe
Forum Newbie
Posts: 8
Joined: Thu Aug 21, 2008 11:16 am

Re: email form

Post by byxbe »

yeah I put that last code in that you sent and the email comes through when I submit the form but the username is not displayed. And it also throws up 2 errors. ->

Warning: Cannot modify header information - headers already sent by (output started at /home/content/........./wholesaleorder.php:2) in /home/content/............./login/functions.php on line 39

Warning: Cannot modify header information - headers already sent by (output started at /home/content/............../wholesaleorder.php:2) in /home/content/......................./wholesaleorder.php on line 22

so i tried redirect_to instead of the 'header' at the bottom but it didnt like that either.
Post Reply