Page 1 of 2
email form
Posted: Thu Aug 21, 2008 11:26 am
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?
Re: email form
Posted: Thu Aug 21, 2008 12:28 pm
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.
Re: email form
Posted: Thu Aug 21, 2008 1:01 pm
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.
Re: email form
Posted: Thu Aug 21, 2008 1:29 pm
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'];
Re: email form
Posted: Thu Aug 21, 2008 1:43 pm
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.
Re: email form
Posted: Thu Aug 21, 2008 1:50 pm
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.
Re: email form
Posted: Thu Aug 21, 2008 2:06 pm
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.
Re: email form
Posted: Thu Aug 21, 2008 2:34 pm
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
Re: email form
Posted: Thu Aug 21, 2008 2:56 pm
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;
}
}
Re: email form
Posted: Thu Aug 21, 2008 2:59 pm
by dajawu
Put my code right above your SQL statement, then in your SQL use the variable instead of that $_POST[$_SESSION[]] stuff.
Re: email form
Posted: Thu Aug 21, 2008 3:15 pm
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");
?>
Re: email form
Posted: Thu Aug 21, 2008 6:33 pm
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:
Re: email form
Posted: Fri Aug 22, 2008 8:28 am
by byxbe
did not work..
Re: email form
Posted: Fri Aug 22, 2008 8:35 am
by dajawu
code?
Re: email form
Posted: Fri Aug 22, 2008 8:42 am
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.