tekrscom Posted June 10, 2007 Share Posted June 10, 2007 I hope that this post belongs in PHP and not in Mysql, if not, I'm sorry... I have a php page that flips between dbs and sometimes it works and sometimes it doesn't... e.g. the first query runs from this db, the second query runs from a different db and then the third query runs from the first db again... the first query will run, the second query will run, but then the third query will not. Each time that I switch to a query that calls a different db, I used include_once "db_whatever"; before the query, thinking that, that would work, but it doesn't... Is there something I need to do to kill the previous db connection prior to moving onto another one? Quote Link to comment Share on other sites More sharing options...
chocopi Posted June 10, 2007 Share Posted June 10, 2007 You could post your code so we can see what you are on about Quote Link to comment Share on other sites More sharing options...
tekrscom Posted June 10, 2007 Author Share Posted June 10, 2007 Ok, but there is lots of it... <?php session_start(); if(!$condition == "logged") { header("Location: login.php"); } elseif($condition == "logged") { if(isset($_POST[week_ending_date])) {$_SESSION[week_ending_date] = date('Y-m-d', strtotime("$_POST[week_ending_date]"));} ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>VASP NA, Inc. Projects</title> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body topmargin="0" leftmargin="0"> <table width="900" cellspacing="0" cellpadding="0" border="0"> <tr> <td valign="top"> <?php include_once "navigation.php" ?> </td> <td width="50"> </td> <td valign="top"> <center> <br> <? include_once "connection_accounts.php"; $directcheckquery = mysql_query("SELECT week_ending_date FROM direct_hours WHERE tech_id = '$_SESSION[userid]' && directontimesheet = '0'"); while ($directcheckrow = mysql_fetch_array($directcheckquery)) { $directcheckcount = mysql_num_rows($directcheckquery); $direct_week_ending_date = $directcheckrow[week_ending_date]; } $indirectcheckquery = mysql_query("SELECT week_ending_date FROM indirect_hours WHERE tech_id = '$_SESSION[userid]' && indirectontimesheet = '0'"); while ($indirectcheckrow = mysql_fetch_array($indirectcheckquery)) { $indirectcheckcount = mysql_num_rows($indirectcheckquery); $indirect_week_ending_date = $indirectcheckrow[week_ending_date]; } if($directcheckcount > 0 || $indirectcheckcount > 0) { echo ' You have an incomplete time sheet for week '; if(!empty($direct_week_ending_date)){echo $direct_week_ending_date;} if(empty($direct_week_ending_date) && !empty($indirect_week_ending_date)){echo $indirect_week_ending_date;} echo '<br><br>'; } if(isset($_SESSION[week_ending_date])) { echo $_SESSION[week_ending_date], '<br><br>'; } else { echo ' <form method="POST" action="', $_SERVER[php_self], '">'; $last = strtotime("last Sunday"); // I have removed the $sunday line because it is not needed for your code for ($i = 1; $i < 3 ;$i++) { $sunarray[] = date("D M j Y", $last); $last = strtotime("+1 Week", $last); } echo '<select name="week_ending_date">'; foreach($sunarray as $var) { echo '<option value="', $var, '">', $var, '</option>'; } echo '</select> <input type="submit" name="submit" value="|"> </form> '; } if(isset($_POST[gold_id])) {$_SESSION[gold_id] = $_POST[gold_id];} if(isset($_POST[project])) {$_SESSION[project] = $_POST[project];} if(isset($_POST[direct_indirect])) {$_SESSION[direct_indirect] = $_POST[direct_indirect];} if(isset($_POST[task_id])) {$_SESSION[task_id] = $_POST[task_id];} if(!empty($_POST[Monday])) {$_SESSION[day] = Monday; $_SESSION[hours] = $_POST['Monday'];} if(!empty($_POST[Tuesday])) {$_SESSION[day] = Tuesday; $_SESSION[hours] = $_POST[Tuesday];} if(!empty($_POST[Wednesday])){$_SESSION[day] = Wednesday; $_SESSION[hours] = $_POST[Wednesday];} if(!empty($_POST[Thursday])) {$_SESSION[day] = Thursday; $_SESSION[hours] = $_POST[Thursday];} if(!empty($_POST[Friday])) {$_SESSION[day] = Friday; $_SESSION[hours] = $_POST[Friday];} if(!empty($_POST[saturday])) {$_SESSION[day] = Saturday; $_SESSION[hours] = $_POST[saturday];} if(!empty($_POST[sunday])) {$_SESSION[day] = Sunday; $_SESSION[hours] = $_POST[sunday];} echo ' <table width="550" cellspacing="2" cellpadding="2" border="0"> <tr> <td> '; if(isset($_SESSION[week_ending_date])) { echo ' <form method="POST" action="', $_SERVER[php_self], '"> <select name="gold_id"> <option value=""> ... </option> '; include_once "connection.php"; $query = mysql_query("SELECT gold_id FROM sites WHERE 1"); while ($row = mysql_fetch_array($query)) { echo '<option'.($row[gold_id] == $_SESSION[gold_id] ? ' selected' : '').' value="', $row[gold_id], '">', $row[gold_id], '</option>'; } echo ' </select> <input type="submit" name="submit" value="|"> </form> '; } else { echo ' <form method="POST" action="', $_SERVER[php_self], '"> <select name="gold_id"> <option value=""> ... </option> </select> <input type="submit" name="submit" value="|"> '; } echo ' </td> <td> <form method="POST" action="', $_SERVER[php_self], '"> <select name="project"> <option value=""> ... </option> '; $query = mysql_query("SELECT project FROM logs WHERE gold_id = '$_SESSION[gold_id]'"); while ($row = mysql_fetch_array($query)) { echo '<option'.($row[project] == $_SESSION[project] ? ' selected' : '').' value="', $row[project], '">', $row[project], '</option>'; } echo ' </select> <input type="submit" name="submit" value="|"> </form> </td> <td> <form method="POST" action="', $_SERVER[php_self], '"> <select name="direct_indirect"> <option value=" ... ">'; if(isset($_SESSION[project])) { echo ' <option'.($_SESSION[direct_indirect] == Direct ? ' selected' : '').' value="Direct"> Direct </option> <option'.($_SESSION[direct_indirect] == InDirect ? ' selected' : '').' value="InDirect"> InDirect </option> '; } echo ' </select> <input type="submit" name="submit" value="|"> </form> </td> <td> <form method="POST" action="', $_SERVER[php_self], '">'; include_once "connection_accounts.php"; $query = mysql_query("SELECT project_id FROM projects WHERE project = '$_SESSION[project]'"); while ($row = mysql_fetch_array($query)) { $_SESSION[project_id] = $row[project_id]; } echo ' <select name="task_id"> <option value=""> ... </option> '; if($_SESSION[direct_indirect] == 'Direct') { $query = mysql_query("SELECT direct_task_id, direct_task FROM direct_tasks WHERE project_id = '$_SESSION[project_id]'"); while ($row = mysql_fetch_array($query)) { echo '<option'.($row[direct_task_id] == $_SESSION[task_id] ? ' selected' : '').' value="', $row[direct_task_id], '">', $row[direct_task], '</option>'; } } if($_SESSION[direct_indirect] == 'InDirect') { $query = mysql_query("SELECT * FROM indirect_tasks WHERE 1"); while ($row = mysql_fetch_array($query)) { echo '<option'.($row[indirect_task_id] == $_SESSION[task_id] ? ' selected' : '').' value="', $row[indirect_task_id], '">', $row[indirect_task], '</option>'; } } echo ' </select> <input type="submit" name="submit" value="|"> </form> </td> </tr> </table> <form method="POST" action="', $_SERVER[php_self], '"> <table width="600" cellspacing="2" cellpadding="2" border="0"> <tr> <td width="70">Monday</td> <td width="70">Tuesday</td> <td width="70">Wednesday</td> <td width="70">Thursday</td> <td width="70">Friday</td> <td width="70">Saturday</td> <td width="70">Sunday</td> <td width="20"> </td> </tr> <tr> <td><input type="text" name="Monday" value="'; if($_SESSION[day] == Monday){echo $_SESSION[hours];} echo'" size="2"></td> <td><input type="text" name="Tuesday" value="'; if($_SESSION[day] == Tuesday){echo $_SESSION[hours];} echo'" size="2"></td> <td><input type="text" name="Wednesday" value="'; if($_SESSION[day] == Wednesday){echo $_SESSION[hours];} echo'" size="2"></td> <td><input type="text" name="Thursday" value="'; if($_SESSION[day] == Thursday){echo $_SESSION[hours];} echo'" size="2"></td> <td><input type="text" name="Friday" value="'; if($_SESSION[day] == Friday){echo $_SESSION[hours];} echo'" size="2"></td> <td><input type="text" name="Saturday" value="'; if($_SESSION[day] == Saturday){echo $_SESSION[hours];} echo'" size="2"></td> <td><input type="text" name="Sunday" value="'; if($_SESSION[day] == Sunday){echo $_SESSION[hours];} echo'" size="2"></td> <td>'; if(isset($_SESSION[task_id])) { echo ' <input type="submit" name="submit" value="Submit"> '; } else { echo ' '; } echo ' </td> </tr> </table> </form> '; if(isset($_SESSION[hours])) { echo ' <form method="POST" action="MTESaction.php"> <table width="750" cellspacing="2" cellpadding="2" border="0"> <tr> <td style="color: PURPLE;" width="70"><b>GOLD ID</b></td> <td style="color: PURPLE;" width="70"><b>Project</b></td> <td style="color: PURPLE;" width="70"><b>Type</b></td> <td style="color: PURPLE;" width="290"><b>Task</b></td> <td style="color: PURPLE;" width="80"><b>Day</b></td> <td style="color: PURPLE;" width="20"><b>Hours</b></td> <td style="color: PURPLE;" width="150"><div align="right"><b>Is This Correct?</b></div></td> </tr> <tr> <td style="color: PURPLE;">', $_SESSION[gold_id], '</td> <td style="color: PURPLE;">', $_SESSION[project], '</td> <td style="color: PURPLE;">', $_SESSION[direct_indirect], '</td>'; if($_SESSION[direct_indirect] == 'Direct') { $query = mysql_query("SELECT direct_task FROM direct_tasks WHERE direct_task_id = '$_SESSION[task_id]'"); while ($row = mysql_fetch_array($query)) { $task = $row[direct_task]; } } if($_SESSION[direct_indirect] == 'InDirect') { $query = mysql_query("SELECT indirect_task FROM indirect_tasks WHERE indirect_task_id = '$_SESSION[task_id]'"); while ($row = mysql_fetch_array($query)) { $task = $row[indirect_task]; } } echo ' <td style="color: PURPLE;">', $task, '</td> <td style="color: PURPLE;">', $_SESSION[day], '</td> <td style="color: PURPLE;">', $_SESSION[hours], '</td> <td><center><input type="submit" name="enter_time" value="Yes"></center></td> </tr> </table> </form> '; } echo ' <br> <br> '; $query = mysql_query("SELECT * FROM direct_hours WHERE tech_id = '$_SESSION[userid]' && week_ending_date = '$_SESSION[week_ending_date]'"); while ($row = mysql_fetch_array($query)) { $directcount = mysql_num_rows($query); } if($directcount > 0) { echo ' <b>Direct Time - ', $_SESSION[week_ending_date], '</b><br> <table width="750" cellspacing="2" cellpadding="2" border="0"> <tr> <td width="70"><b>GOLD ID</b></td> <td width="70"><b>Project</b></td> <td width="70"><b>Type</b></td> <td width="290"><b>Task</b></td> <td width="80"><b>Day</b></td> <td width="20"><b>Hours</b></td> </tr> '; } $query = mysql_query("SELECT * FROM direct_hours WHERE tech_id = '$_SESSION[userid]' && week_ending_date = '$_SESSION[week_ending_date]'"); while ($row = mysql_fetch_array($query)) { echo ' <tr> <td style="color: RED;">', $row[gold_id], '</td> <td style="color: RED;"> '; $secondquery = mysql_query("SELECT project FROM projects WHERE project_id = '$row[project_id]'"); while ($secondrow = mysql_fetch_array($secondquery)) { echo $secondrow[project]; } echo ' </td> <td style="color: RED;">Direct</td> <td style="color: RED;"> '; $thirdquery = mysql_query("SELECT direct_task FROM direct_tasks WHERE direct_task_id = '$row[task_id]'"); while ($thirdrow = mysql_fetch_array($thirdquery)) { echo $thirdrow[direct_task]; } echo ' </td> <td style="color: RED;">', $row[week_ending_date_day], '</td> <td style="color: RED;">', $row[direct_hours], '</td> </tr> '; } if($directcount > 0) { echo ' </table><br><br> '; } $fourthquery = mysql_query("SELECT * FROM indirect_hours WHERE tech_id = '$_SESSION[userid]' && week_ending_date = '$_SESSION[week_ending_date]'"); while ($row = mysql_fetch_array($fourthquery)) { $indirectcount = mysql_num_rows($fourthquery); } if($indirectcount > 0) { echo ' <b>InDirect Time - ', $_SESSION[week_ending_date], '</b><br> <table width="750" cellspacing="2" cellpadding="2" border="0"> <tr> <td width="70"><b>GOLD ID</b></td> <td width="70"><b>Project</b></td> <td width="70"><b>Type</b></td> <td width="290"><b>Task</b></td> <td width="80"><b>Day</b></td> <td width="20"><b>Hours</b></td> </tr> '; } $fifthquery = mysql_query("SELECT * FROM indirect_hours WHERE tech_id = '$_SESSION[userid]' && week_ending_date = '$_SESSION[week_ending_date]'"); while ($row = mysql_fetch_array($fifthquery)) { echo ' <tr> <td style="color: RED;">', $row[gold_id], '</td> <td style="color: RED;"> '; $sixthquery = mysql_query("SELECT project FROM projects WHERE project_id = '$row[project_id]'"); while ($secondrow = mysql_fetch_array($sixthquery)) { echo $secondrow[project]; } echo ' </td> <td style="color: RED;">InDirect</td> <td style="color: RED;"> '; $seventhquery = mysql_query("SELECT indirect_task FROM indirect_tasks WHERE indirect_task_id = '$row[task_id]'"); while ($thirdrow = mysql_fetch_array($seventhquery)) { echo $thirdrow[indirect_task]; } echo ' </td> <td style="color: RED;">', $row[week_ending_date_day], '</td> <td style="color: RED;">', $row[indirect_hours], '</td> </tr> '; } if($indirectcount > 0) { echo ' </table> '; } if($indirectcount > 0 || $directcount > 0) { echo ' <br><br> <center> <form method="POST" action="MTESaction.php"> <input type="submit" name="submittal" value="Submit Time Sheet For Approval"> </form> </center> '; } ?> </td> </tr> </table> <?php } ?> Notice how I start off with include_once connection_accounts.php; and then go to include_once connection.php; and then have to go back to include_once connection_accounts.php; again. Quote Link to comment Share on other sites More sharing options...
Hypnos Posted June 10, 2007 Share Posted June 10, 2007 Replace include_once with include. You are including more than once. include_once blocks that. Quote Link to comment Share on other sites More sharing options...
tekrscom Posted June 10, 2007 Author Share Posted June 10, 2007 Thank you so very much, I've been trying everything... Hate it when it turns out to be something so simple, but at least a learning experience... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.