twilitegxa Posted September 26, 2008 Share Posted September 26, 2008 I have this form that asks for user's questions and/or comments, and then I have it display on a page. What I want to do is have a link for me to respond to these questions or comments. I have the page set up, but I can't figure out how to pull the e-mail address from the displayed results. I'm assuming I need to name a variable, but how can I pull the e-mail address from the displayed information? Please help! Here is the display page code: <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("smrpg", $con); // Get all the data from the "guestbook" table $result = mysql_query("SELECT * FROM contact ORDER BY commentdate DESC") or die(mysql_error()); $email = $row['email']; echo "<h1>Sailor Moon RPG Questions/Comments - View</h1>"; echo "<table border='0'>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td width='15%'>"; echo "<b>Name:</b></td><td>"; echo $row['name']; echo "</td></tr><tr><td>"; echo "<b>E-mail:</b></td><td>"; echo $row['email']; echo "</td></tr><tr><td>"; echo "<b>Question/Comment:</b></td><td>"; echo $row['question']; echo "</td></tr><tr><td>"; echo "<b>Date & Time:</b></td><td>"; echo date("F j, Y @ g:i A T",strtotime($row['commentdate'])); echo "</td></tr>"; echo "<tr><td><a href='mailto:$email'>Respond</a>?</td></tr>"; echo "<tr><td> </td></tr>"; } echo "</table>"; ?> Quote Link to comment Share on other sites More sharing options...
knox203 Posted September 26, 2008 Share Posted September 26, 2008 I would do this (if I understand what you're trying to do correctly...): <?php $con = mysql_connect("localhost","root","") or die('Could not connect: ' . mysql_error()); mysql_select_db("smrpg", $con); // Get all the data from the "guestbook" table $result = mysql_query("SELECT * FROM contact ORDER BY commentdate DESC") or die(mysql_error()); echo "<h1>Sailor Moon RPG Questions/Comments - View</h1>"; echo "<table border='0'>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td width='15%'>"; echo "<b>Name:</b></td><td>"; echo $row['name']; echo "</td></tr><tr><td>"; echo "<b>E-mail:</b></td><td>"; echo $row['email']; echo "</td></tr><tr><td>"; echo "<b>Question/Comment:</b></td><td>"; echo $row['question']; echo "</td></tr><tr><td>"; echo "<b>Date & Time:</b></td><td>"; echo date("F j, Y @ g:i A T",strtotime($row['commentdate'])); echo "</td></tr>"; echo "<tr><td><a href='mailto:".$row['email']."'>Respond</a>?</td></tr>"; echo "<tr><td> </td></tr>"; } echo "</table>"; ?> It looked like you were trying to define "$email" before there was even a result array (mysql_fetch_array() was below the variable you were trying to define). Instead of creating a variable... we can just display the data straight from the result set using concatenation. Also, you don't need to use an 'if' statement during your connection string, simply using "or die()" will accomplish the same thing with less code. Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted September 26, 2008 Author Share Posted September 26, 2008 Thank you! That is exactly what I wanted to do! Quote Link to comment 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.