Forum Moderators: coopster
Here is the page that calls on MySQL.
<?
//Connect to the Mysql Server and select the database
$username="##";
$password="##";
$database="##";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
//Run a query
$query="SELECT cell.name FROM table WHERE id = '##'";
$result= @mysql_query ($query);
//Get the result
if ($result) {
echo '<table><tr><td>';
while ($row=mysql_fetch_row($result)) {
print "$row[0]";
</td></tr>';
}
echo '</table>';
}
?>
The code that is stored in MySQL:
<a href="http://www.mySite.com/somepage.php?id="$_GET['id']" target="_blank">
Can someone help me out?
-Thanks,
Chris
I'll warn you that eval isn't a function to cut your PHP teeth on. When you use it, it's crucial that the argument be valid PHP code. Try running this test to get the hang of it.
The value I've given to $row[0] is the kind of valid code that you'll be required to have in your database in order for eval to work. Getting it in there, however, is another matter. $_GET['id'] = 123; // first two lines are just to fake some values
$row[0] = '<a href=\"http://www.mySite.com/somepage.php?id=\"'.$_GET['id'].'\" target=\"_blank\">Added an anchor closing for testing.</a>';
eval("\$row[0] = \"$row[0]\";");
print $row[0]. "<br>\n";
print htmlspecialchars($row[0]). "<br>\n"; // see that 123 is in there
I hope this helps.
Something that no one has asked you, Woemlavy, is why are you doing this? My favorite quote from the php.net eval() page is:
If eval() is the answer, you're almost certainly asking the wrong question. -- Rasmus Lerdorf
Well, of course, I did have to test it, and this does work:
$row[0] = '<a href=\"http://www.mySite.com/somepage.php?id=$_GET[id]\" target=\"_blank\">Added an anchor closing for testing.</a>';
echo $row[0]. "<br>\n";
print htmlspecialchars($row[0]). "<br>\n";
$_GET['id'] = 123;
eval("\$row[0] = \"$row[0]\";");
print $row[0]. "<br>\n";
print htmlspecialchars($row[0]). "<br>\n"; /// see that 123 is in there