Hi there. I'm relatively new to PHP (only been coding a couple of weeks) and I've managed to struggle through most problems and issues myself until now, but tonight I ran across a problem that I can't solve. I wonder if someone can help me?
I'm creating a menu by drawing a list of titles that are stored in a database using a PHP mySQL query. I then use those titles as hyperlinks to populate a <DIV> layer on the same page.
After connecting to the database and populating an array called $arrReturneddata with the titles, I build the menu using the following code:
while ($row=mysql_fetch_array($arrReturneddata))
{
echo "<div id={$row['title']} class=\"menutext\"><a href = \"$PHP_SELF?testvariable={$row['title']}\">{$row['title']}</a></div>";
}
Then I check to see whether the page is passing the testvariable back to itself when the hyperlink is clickedand take appropriate action:
if (! isset ($testvariable))
{
echo "<div id=\"listendescription\" style=\"position:absolute; left:230px; top:145px; width:332px; height:178px; z-index:11; overflow: visible; padding = 5px\" class=\"listentext\">";
echo "Text to display when there's no record data";
echo "</div>";
}
if (isset ($testvariable))
{
connect('user_name', 'password', 'database_name');
$arrReturneddata = & getdata('table_name','field_name', $testvariable, 'broadcast_date');
$row=mysql_fetch_array($arrReturneddata);
// Display 'Description' text field
echo "<div id=\"listendescription\" style=\"position:absolute; left:230px; top:145px; width:332px; height:178px; z-index:11; overflow: visible; padding = 5px\" class=\"listentext\">";
echo "</div>";
The 'no record data' text comes up every time - the test variable isn't being set and so my records aren't being displayed. What's weird is that I had the site fully developed at home on my local network, running against Apache and MySQL on a Windows XP machine. The variable was passed and everything was fine -- it was set and I got my record data back. It's only when running it on my ISP's Unix-based server that it doesn't work. My ISP is very strict on security settings, to the point of not even giving his clients TELNET access, so I'm wondered if his PHP implementation has a critical feature turned off. I know that he said he had globals disabled, for example, but I'm not sure if this would be the problem.
Should I try to do this using the PHP session management facilities instead?
I'm still a newbie so if somene could advise me I'd appreciate the help.
g.
PS just for completeness, here are my 'connect' and 'getdata' functions, but I'm pretty sure these are working because I don't get a 'couldn't connect' error message, and I get the initial menu titles back from the database ok - it's only the variable passing that seems to cause problems.
function connect ($user, $password, $D😎
{
define('MYSQL_HOST', 'localhost');
if (! mysql_connect(MYSQL_HOST, $user, $password))
{
die('Failed to connect to host "' . MYSQL_HOST . '".');
}
mysql_select_db($D😎;
}
function & getdata ($searchDB, $searchfield, $criteria, $order_var)
{ //Gets data from field $searchfield in database $searchDB, using $criteria
//get everything if $criteria = All
if ($criteria == "All")
{
$result=mysql_query ("SELECT $searchfield FROM $searchDB ORDER BY $order_var DESC");
}
else
{
$result=mysql_query ("SELECT * FROM $searchDB WHERE $searchfield = '$criteria' ORDER BY $order_var DESC");
}
return $result;
}