good day! i'm an old member of this forum but unfortunately i forgot both my email and pw. >< so i created another account. :)

with all due respect is there somebody who can help me with this code. i've created a menu link from the database

<?php
$con = mysql_connect("localhost","portal","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("stroman", $con);
$result = mysql_query("SELECT * FROM sample");
while($row = mysql_fetch_array($result))
  {
  echo "<a name='".$row['name']."'"."href='viewlink.php'>". $row['name'] ."</a>". " | " ;
  }
mysql_close($con);
?>

the output is this:
example | example

the problem is, i want to show the content of the link from the database to another page. this is my code

<?php
$a=$row['name'];


$con = mysql_connect("localhost","portal","");
if (!$con)
	{
	die('Could Not Connect: ' . mysql_error());
	}

mysql_select_db("stroman", $con);

$result = mysql_query("SELECT * FROM sample WHERE name='$a'");

while($row = mysql_fetch_array($result))
{
echo "<center>";
echo "<h1>". $row['name'] . "</h1>";
echo "<br /><br />";
echo "<img width='250' height='250' src='pictures/".$row['filename']."'/>";
echo "<br /><br />";
echo "<pre>". $row['recipe']."</pre>";
echo "</center>";
}
?>

i want to simply create a menu but from database. thank you so much for your help

Why don't you assign name into a global variable $a before you close the connection on line 13 (part one) i.e. place this line

$a=$row['name'];

after line 12. Alternatively use the same statement on the other page.

You won't get anything as their is no such variable as $row. You need to add the $a variable to the end of your link url (why are you using the name parameter in the link??):

echo "<a href='viewlink.php?name=".$row['name']."'>". $row['name'] ."</a>". " | " ;

And on your receiving page:

$a = $_GET['name'];

And then use $a throughout the script where you are currently using $row

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.