Jump to content

[SOLVED] Naming variable help


twilitegxa

Recommended Posts

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>";
?>

Link to comment
Share on other sites

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.

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.