View Full Version : Problems passing variables between pages
i4VisualMedia
12-14-2006, 01:14 PM
Hi Guys
I am trying to pass a varible (namely the ID of the database entry) between two pages using the following:
$output = "<a href='memberedit?id=".$row['id']."'>Edit</a>";
echo $output;
When the link is clicked, I am being taken to the address:
www.mydomain.com/memberedit?id=
note the missing ID.
Can anybody help?
incase you need it, my query is as follows:
$query = "SELECT ID,company FROM `members`";
Cheers guys
Pete
Tyree
12-14-2006, 01:37 PM
Let's see how you're setting $row.
Also, if your fieldname is 'ID', then your call for that field in the $row array should be $row['ID']. Don't change cases.
i4VisualMedia
12-14-2006, 01:42 PM
Hi,
my entire code is as follows:
<?php
require_once('../includes/DbConnector.php');
$connector = new DbConnector();
$query = "SELECT ID,company FROM `members`";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
$output = "<a href='memberedit?id=".$row['id']."'>Edit</a>";
for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
echo ' <br /><br />';
echo ($row['company']);
echo ' '.$output;
}
?>
Cheers
Pete
i4VisualMedia
12-14-2006, 01:45 PM
forgot, just changed the id to ID in
$output = "<a href='memberedit?id=".$row['ID']."'>Edit</a>";
Still doesnt work.
mic2100
12-14-2006, 02:07 PM
<?php
require_once('../includes/DbConnector.php');
$connector = new DbConnector();
$query = "SELECT ID,company FROM `members`";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
//the row need to be fetched before you can call values from it.
$row = mysql_fetch_assoc($result);
do
{
//don't have this here $row = mysql_fetch_array($result);
$output = "<a href='memberedit?id=".$row['ID']."'>Edit</a>";
echo ' <br /><br />';
echo ($row['company']);
echo ' '.$output;
}while($row = mysql_fetch_assoc($result));
?>
Hope this helps
Tyree
12-14-2006, 02:10 PM
Put the definition for $output inside the for loop:
<?php
require_once('../includes/DbConnector.php');
$connector = new DbConnector();
$query = "SELECT ID,company FROM `members`";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
for ($i=0; $i <$num_results; $i++)
{
$output = "<a href='memberedit?id=".$row['ID']."'>Edit</a>";
$row = mysql_fetch_array($result);
echo ' <br /><br />';
echo ($row['company']);
echo ' '.$output;
}
?>
$row['ID'] didn't know what it was outside the loop. :)
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.