aebstract Posted March 14, 2007 Share Posted March 14, 2007 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: [email protected]'); 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! Quote Link to comment https://forums.phpfreaks.com/topic/42741-solved-passing-variables-through-a-form/ Share on other sites More sharing options...
aebstract Posted March 15, 2007 Author Share Posted March 15, 2007 bump^ + What would be the easiest way to get those variables through when I click the link? I can go through url if I have to, I just thought I could do hidden fields? Quote Link to comment https://forums.phpfreaks.com/topic/42741-solved-passing-variables-through-a-form/#findComment-207958 Share on other sites More sharing options...
utherwun Posted March 15, 2007 Share Posted March 15, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/42741-solved-passing-variables-through-a-form/#findComment-207962 Share on other sites More sharing options...
aebstract Posted March 15, 2007 Author Share Posted March 15, 2007 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: [email protected]'); 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 Quote Link to comment https://forums.phpfreaks.com/topic/42741-solved-passing-variables-through-a-form/#findComment-207965 Share on other sites More sharing options...
markbett Posted March 15, 2007 Share Posted March 15, 2007 ok lets try this approach,,, what are you expecting to have happen and what is actually happening?? Quote Link to comment https://forums.phpfreaks.com/topic/42741-solved-passing-variables-through-a-form/#findComment-207974 Share on other sites More sharing options...
aebstract Posted March 15, 2007 Author Share Posted March 15, 2007 I'm expecting that when you fill out the form, it should send an email to the person. It should also update the database, it should update the row with the specific unique id and change readc to 1. Neither of which it is doing. Quote Link to comment https://forums.phpfreaks.com/topic/42741-solved-passing-variables-through-a-form/#findComment-207976 Share on other sites More sharing options...
aebstract Posted March 15, 2007 Author Share Posted March 15, 2007 O.o Quote Link to comment https://forums.phpfreaks.com/topic/42741-solved-passing-variables-through-a-form/#findComment-208177 Share on other sites More sharing options...
aebstract Posted March 15, 2007 Author Share Posted March 15, 2007 Does anyone see anything at all? Quote Link to comment https://forums.phpfreaks.com/topic/42741-solved-passing-variables-through-a-form/#findComment-208208 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.