Jump to content

[SOLVED] passing variables through a form


aebstract

Recommended Posts

Hello again,

I have a setup where I am displaying lots of information, all of it comes from contact forms and is stored in a database. Then can be viewed on one page, through the scripts. One feature is that you can click on an email address to send an email to that specific user. When you click their email, the form comes up fine, and I have been playing with this for awhile.. I am having trouble getting the variables passed through so that I can send the email and update the database. If anyone could take a look at my code that would be great.

 

<?php
header("Cache-control: private");
?>
<html>
<head>
<link href="stylesheet.css" rel="stylesheet" type=text/css title=default />
</head>
<body>
<div id="concon">
<?php

mysql_connect("localhost","hmg","hillpass"); 
mysql_select_db("hmg"); 


if (isset ($_POST['submit'])) {
$msg = $_POST['msg'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$mail = $_POST['mail'];


$query = "UPDATE contact SET readc='1' WHERE id=$mail;";
mysql_query($query);


mail ($email, 'Reply from HMG', $msg, 'From: info@hillmarketinggroup.com');
header ("Location: readmail.php");

}


$mark = $_GET['mark'];
if (isset($mark)) {
$query = "UPDATE contact SET readc='1' WHERE id=$mark;";
mysql_query($query);

header("Location: readmail.php");
}



$mail = $_GET['mail'];
if (isset($mail)) {

$result = mysql_query("SELECT * FROM contact WHERE id=$mail") or DIE(mysql_error());
while($r=mysql_fetch_array($result)) 
{ 
$id=$r["id"];
$firstname=$r["firstname"];
$lastname=$r["lastname"];
$email=$r["email"];
$body=$r["body"];

echo "
<div id=uploadform>
<table>
<tr>
<td align=right>To:</td><td width=5></td><td>$firstname $lastname</td>
</tr><tr>
<td></td><td></td><td>$email</td>
</tr><tr>
<td></td><td></td><td>
<form action=readmail.php method=post>
<input name=$mail type=hidden value=$mail>
<input name=$firstname type=hidden value=$firstname>
<input name=$lastname type=hidden value=$lastname>
<input name=$email type=hidden value=$email>
<textarea name=msg rows=5 cols=60></textarea><br />
<input type=submit name=submit value=Send />
</form>
</td>
</tr>
</table>
<div align=right><a href=readmail.php>back</a></div>
</div>
";

}

} else {


$result = mysql_query("SELECT * FROM contact WHERE readc='0' ORDER BY id ASC") or DIE(mysql_error());
while($r=mysql_fetch_array($result)) 
{ 
$id=$r["id"];
$typec=$r["typec"];
$readc=$r["readc"];
$firstname=$r["firstname"];
$lastname=$r["lastname"];
$email=$r["email"];
$body=$r["body"];
$company=$r["company"];
$website=$r["website"];
$telephone=$r["telephone"];
$address=$r["address"];
$city=$r["city"];
$state=$r["state"];
$zip=$r["zip"];

if ($typec == 0) {
echo "
<div class=\"contactdivred\"><a href=readmail.php?mark=$id>UNREAD</a></div>
<div class=\"contactdiv\">
<table class=\"contfont\">
<tr>
<td align=right>Name:</td><td width=5></td><td>$firstname $lastname</td>
</tr><tr>
<td align=right>Email:</td><td></td><td><a href=readmail.php?mail=$id>$email</a></td>
</tr><tr>
<td align=right valign=top>Message:</td><td></td><td>$body</td>
</tr>
</table>
</div>
";
} else {
echo "
<div class=\"contactdivred\"><a href=readmail.php?mark=$id>UNREAD</a></div>
<div class=\"contactdiv\">
<table class=\"contfont\">
<tr>
<td align=right>Name:</td><td width=5></td><td>$firstname $lastname</td>
</tr><tr>
<td align=right>Email:</td><td></td><td><a href=readmail.php?mail=$id>$email</a></td>
</tr><tr>
<td align=right valign=top>Message:</td><td></td><td>$body</td>
</tr><tr>
<td></td><td></td><td></td>
</tr><tr>
<td></td><td></td><td></td>
</tr><tr>
<td></td><td></td><td></td>
</tr><tr>
<td align=right>Company:</td><td></td><td>$company</td>
</tr><tr>
<td align=right>Website:</td><td></td><td>$website</td>
</tr><tr>
<td align=right>Telephone:</td><td></td><td>$telephone</td>
</tr><tr>
<td align=right>Address:</td><td></td><td>$address</td>
</tr><tr>
<td align=right>City:</td><td></td><td>$city</td>
</tr><tr>
<td align=right>State:</td><td></td><td>$state</td>
</tr><tr>
<td align=right>ZIP:</td><td></td><td>$zip</td>
</tr>
</table>
</div>
";
}

}




$result = mysql_query("SELECT * FROM contact WHERE readc='1' ORDER BY id DESC") or DIE(mysql_error());
while($r=mysql_fetch_array($result)) 
{ 
$id=$r["id"];
$typec=$r["typec"];
$readc=$r["readc"];
$firstname=$r["firstname"];
$lastname=$r["lastname"];
$email=$r["email"];
$body=$r["body"];
$company=$r["company"];
$website=$r["website"];
$telephone=$r["telephone"];
$address=$r["address"];
$city=$r["city"];
$state=$r["state"];
$zip=$r["zip"];

if ($typec == 0) {
echo "
<div class=\"contactdiv\">
<table class=\"contfont\">
<tr>
<td align=right>Name:</td><td width=5></td><td>$firstname $lastname</td>
</tr><tr>
<td align=right>Email:</td><td></td><td><a href=readmail.php?mail=$id>$email</a></td>
</tr><tr>
<td align=right valign=top>Message:</td><td></td><td>$body</td>
</tr>
</table>
</div>
";
} else {
echo "
<div class=\"contactdiv\">
<table class=\"contfont\">
<tr>
<td align=right>Name:</td><td width=5></td><td>$firstname $lastname</td>
</tr><tr>
<td align=right>Email:</td><td></td><td><a href=readmail.php?mail=$id>$email</a></td>
</tr><tr>
<td align=right valign=top>Message:</td><td></td><td>$body</td>
</tr><tr>
<td></td><td></td><td></td>
</tr><tr>
<td></td><td></td><td></td>
</tr><tr>
<td></td><td></td><td></td>
</tr><tr>
<td align=right>Company:</td><td></td><td>$company</td>
</tr><tr>
<td align=right>Website:</td><td></td><td>$website</td>
</tr><tr>
<td align=right>Telephone:</td><td></td><td>$telephone</td>
</tr><tr>
<td align=right>Address:</td><td></td><td>$address</td>
</tr><tr>
<td align=right>City:</td><td></td><td>$city</td>
</tr><tr>
<td align=right>State:</td><td></td><td>$state</td>
</tr><tr>
<td align=right>ZIP:</td><td></td><td>$zip</td>
</tr>
</table>
</div>
";
}

}
}
?>

</div>
</body>
</html>

 

Most of the mailing stuff if near the top.

Thanks!

Link to comment
Share on other sites

As far as I know, albeit only a little, but the only way you can send hidden items and keep them hidden is by submitting them via a form and using $_POST. I've had to do this for several pages utilizing Javascript as presubmit verification and recalling a PHP script to basically display another page.

 

I know it's basic but possibly something overlooked... hope it helps some. :)

 

edit: And apparently I can't read for comprehension either. :embarassed:

 

Does the readmail.php use $_POST data to get the information or is it just reloading the same page? I'm getting a little lost in the code.  Also, is it giving you any specific error?

Link to comment
Share on other sites

See, that is what I am trying to do, is pass them through a form.. though I am coming up short. I'll try and post the bits that are dealing with that here to make it easier to see:

 

 

This part is after you click send on the form, ( the if submit comes in to play )

if (isset ($_POST['submit'])) {
$msg = $_POST['msg'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$mail = $_POST['mail'];


$query = "UPDATE contact SET readc='1' WHERE id=$mail;";
mysql_query($query);


mail ($email, 'Reply from HMG', $msg, 'From: info@hillmarketinggroup.com');
header ("Location: readmail.php");

}


$mark = $_GET['mark'];
if (isset($mark)) {
$query = "UPDATE contact SET readc='1' WHERE id=$mark;";
mysql_query($query);

header("Location: readmail.php");
}

 

 

 

 

Okay, here is the part where, when you click an email address on the main section, you get this form:

$mail = $_GET['mail'];
if (isset($mail)) {

$result = mysql_query("SELECT * FROM contact WHERE id=$mail") or DIE(mysql_error());
while($r=mysql_fetch_array($result)) 
{ 
$id=$r["id"];
$firstname=$r["firstname"];
$lastname=$r["lastname"];
$email=$r["email"];
$body=$r["body"];

echo "
<div id=uploadform>
<table>
<tr>
<td align=right>To:</td><td width=5></td><td>$firstname $lastname</td>
</tr><tr>
<td></td><td></td><td>$email</td>
</tr><tr>
<td></td><td></td><td>
<form action=readmail.php method=post>
<input name=$mail type=hidden value=$mail>
<input name=$firstname type=hidden value=$firstname>
<input name=$lastname type=hidden value=$lastname>
<input name=$email type=hidden value=$email>
<textarea name=msg rows=5 cols=60></textarea><br />
<input type=submit name=submit value=Send />
</form>
</td>
</tr>
</table>
<div align=right><a href=readmail.php>back</a></div>
</div>
";

}

} else {

 

I closed that bit of code off at the else, because the first part you go to when visiting this page is in that else.

Hope this helps out so that I can get some help :P

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.