Hey guys, newbie here!
I am having trouble entering code into a function. I have code on a page that calls a function. The code works fine as a top down script without calling a function. When I break it down to call a function it crashes with a MySQL error of:
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /development/includes/functions.php on line 34
This is line 34:also shown below.
$rs_nav_menu_s1 = mysql_query($query_nav_menu_s1, $db_database) or die(mysql_error());
Here is the code that is defining and calling the function:
<?php
$db_hostname = "localhost";
$db_database = "xxxx";
$db_username = "xxxx";
$db_password = "xxxx";
$db_connect = mysql_connect($db_hostname, $db_username, $db_password) or die(mysql_error());
draw_section($db_hostname, $db_database, $db_username, $db_password, $db_connect); ?>
Here is the code of the function: it is a partial list showing th first part where it crashes.
function draw_section($db_hostname, $db_database, $db_username, $db_password, $db_connect)
{
mysql_select_db($db_database, $db_connect);
$query_nav_menu_s1 = "SELECT * FROM nav_menu_s1 WHERE section_id = 1 ORDER by position_id";
$rs_nav_menu_s1 = mysql_query($query_nav_menu_s1, $db_database) or die(mysql_error());
$row_rs_nav_menu_s1 = mysql_fetch_assoc($rs_nav_menu_s1);
$totalRows_rs_nav_menu_s1 = mysql_num_rows($rs_nav_menu_s1);
$drawn_section="style type='text/css'>#s" . $row_rs_nav_menu_s1['section_id'] . " {visibility:hidden; position:absolute; left:5; top:93; width:145; height:" . (17*$totalRows_rs_nav_menu_s1)+18 . "; clip:rect(0,145," . (17*$totalRows_rs_nav_menu_s1)+18 . ",0); background-color:#EAEAEA; layer-background-color:#EAEAEA; z-index:90;}</style>";
Is it not possible to call a db connection in a function? Anyone have any ideas why this will not work?
Thanks
TS