ThePilots81 Posted February 5, 2008 Share Posted February 5, 2008 I'm somewhat new at programming and I'm writing a simple program to be used on the intranet at my work that will allow anyone with access to the intranet the ability to run the different scripts needed to update the database. I have a couple problems that I am unable to figure out. Everyone uses Firefox here, so that's the browser I need this program to work with. The program queries the database to get the scripts that need to be run and lists them out in a table with the files that they require in order to run. The user uploads the required files and then selects the radio button for the script they want to run and clicks the Run Selected button at the bottom of the table. Everything works except for the file upload form for the first script that is listed in the table. All the file upload forms work for each script after the first one. It doesn't matter what script it is, but it's always the first script that doesn't work. If I comment out the start form tag for the entire table, then that first file upload form works properly, but then the Run Selected button at the bottom of the page doesn't work. But if I don't edit out the form tag and I move it anywhere else, the Run Selected button doesn't work. Any ideas? The form line below that causes the problem is: echo "<form value='SR_ScriptRunnerTest.php' method='post'>"; // start form I've attached the code below. I would appreciate any help or feedback. Thanks! <?php $radioset = $_REQUEST["radioset"]; $run = $_REQUEST["run"]; $File1 = $_REQUEST["File1"]; if (!empty($File1)) echo "<font align='center'>*File <font color='red'>$File1</font> was uploaded successfully*</font>"; $Date = mktime(0, 0, 0, date("m"), date("d"), date("Y")); $Today = date("Y-m-d",$Date); $query = "SELECT ScriptName, ScriptDescription, FileType1, FileType2, DATE_FORMAT(NextRunTime, '%m-%d-%Y'), DATE_FORMAT(LastRunTime, '%m-%d-%Y<br>%l:%i %p'), Category, RunOrder FROM sr_scriptrunner where LastRunTime < \"$Today\" and Category=\"Today\" ORDER BY RunOrder ASC"; $result = mysql_query($query) or die(mysql_error()); // layout results from query $number_rows = mysql_num_rows($result); if ($number_rows == 0) echo "<h3 align='center'><font>No scripts need to be run at this time.</font></h3><br>"; else if ($number_rows > 0) { // start table header for today echo "<br>\n"; echo "<form value='SR_ScriptRunnerTest.php' method='post'>"; // start form (this is the problem) echo "<table border='2' bordercolor='black' width='100%' align='center'>\n"; // start table echo "<tr>\n"; // start row echo "<th>Select</th>\n"; // column title echo "<th>Script Description</th>\n"; // column title echo "<th>Upload File(s)</th>\n"; // column title echo "<th>Upload</th>\n"; // column title echo "<th>Files Required</th>\n"; // column title echo "<th>Next Run Date</th>\n"; // column title echo "<th>Last Run Time</th>\n"; // column title echo "<th>View<br>History</th>\n"; // column title while ($row = mysql_fetch_row($result)) { list($ScriptName, $ScriptDescription, $FileType1, $FileType2, $NextRunTime, $LastRunTime, $Category, $RunOrder) = $row; echo "</tr>\n"; // end row echo "<tr>\n"; // start row $FileName1 = $FileType1.'.csv'; if (!empty($FileType2)) $FileName2 = $FileType2.'.csv'; else $FileName2 = ""; file_exists("uploads/$FileName1"); // check to see if file exists for conditional file_exists("uploads/$FileName2"); // displaying the select box DISABLED or not echo "<td align='center'>"; if (file_exists("uploads/$FileName1") && file_exists("uploads/$FileName2")) echo "<input type='radio' name='radioset' value='$ScriptName'>"; // checkbox field else echo "<input type='radio' name='radioset' value='$ScriptName' DISABLED>"; // selectbox field echo "</td>\n"; // end row echo "<td align='left'>"; // start row echo "<A onMouseover=\"stm('Instructions','1) Upload file(s) listed under FILES REQUIRED<br>2) Select script to be run<br>3) Click RUN SELECTED<br>See HELP link above for more information',Style[9])\" onMouseOut=\"htm()\"\n>"; if (file_exists("uploads/$FileName1") && file_exists("uploads/$FileName2")) echo "<font color='green'>$ScriptName:</font> $ScriptDescription"; // script description field else echo "<font color='red'>$ScriptName:</font> $ScriptDescription"; // script name and description display echo "</a>"; echo "</td>\n"; // end row if ((!file_exists("uploads/$FileName1")) or (!file_exists("uploads/$FileName2"))) { echo "<td align='center' valign='middle'>"; // displays upload form echo "<form action='SR_UploadFile.php?Category=$Category' method='post' enctype='multipart/form-data'>"; echo "<label for='file'></label>"; echo "<input type='file' name='file' size='10' id='file'>"; echo "</td>"; } else { echo "<td align='center' valign='middle'>"; echo "<font color='black'>All Files Uploaded</font>"; echo "</td>"; } if ((!file_exists("uploads/$FileName1")) or (!file_exists("uploads/$FileName2"))) { echo "<td align='center' valign='middle'>"; // displays upload button echo "<input type='submit' name='submit' value='Upload'>"; echo "</td>"; } else { echo "<td align='center' valign='middle'>"; echo "<input type='submit' name='submit' value='Upload' DISABLED>"; echo "</td>"; } echo "</form>"; echo "<td align='center'>"; // display required file name if (file_exists("uploads/$FileName1") && file_exists("uploads/$FileName2")) echo "<font color=green>$FileName1<br>$FileName2</font>"; else echo "<font color=red>$FileName1<br>$FileName2</font>"; echo "</td>\n"; echo "<td align='center'>"; echo $NextRunTime; // display next run date echo "</td>\n"; echo "<td align='center'>"; if (!empty($LastRunTime)) echo $LastRunTime; // display last run time else echo "No record"; echo "</td>\n"; echo "<td align=\"middle\">"; // view upload history link echo "<A HREF=\"SR_History.php?ScriptName=$ScriptName\" title=\"Click here to view history for this script\" target=\"_blank\"><img border=0 src=\"sr_history.jpg\"></A>"; echo "</td>\n"; } // end while echo "</table>"; // end table for today's scripts if ($number_rows <> 0) echo "<br><input type='submit' name='run' value='Run Selected'><br><br></form>"; // Run Selected scripts button } // end number rows if ((!empty($run)) and ($run == 'Run Selected')) { if (!empty($radioset)) { // conditions for running script $IncludeFile = $radioset.'.php'; echo "Running: ",$IncludeFile; echo "<br>"; include ($IncludeFile); // include script file echo "<br>"; echo "<br>"; echo "<br>"; echo "<br>"; echo "<br>"; echo "<br>"; echo "<br>"; echo "<br>"; echo "<br>"; echo "End Execution of: ",$IncludeFile; } // query to rename uploaded files $query = "Select FileType1, FileType2 from callcenter.sr_scriptrunner where ScriptName = \"$radioset\""; $result = mysql_query($query) or die (mysql_error()); $number_rows = mysql_num_rows($result); while ($row = mysql_fetch_row($result)) { list($FileType1, $FileType2) = $row; $File1 = $Today.'.csv'; $File2 = $Today.'.csv'; rename("uploads/$FileType1.csv", "uploads/$FileType1 $File1"); // rename files after upload if (!empty($FileType2)) { rename("uploads/$FileType2.csv", "uploads/$FileType2 $File2"); } } $FileInfo = date('Y-m-d H:i'); $Tomorrow = mktime(0, 0, 0, date("m"), date("d")+1, date("Y")); // get date to load into database with the following query $Schedule = date('Y-m-d',$Tomorrow); // update last run time and next run time in db $query = "UPDATE callcenter.sr_scriptrunner SET LastRunTime=\"$FileInfo\", NextRunTime=\"$Schedule\" WHERE ScriptName=\"$radioset\""; $result = mysql_query($query) or die (mysql_error()); } echo "</body>"; echo "</html>"; ?> Quote Link to comment Share on other sites More sharing options...
rhodesa Posted February 5, 2008 Share Posted February 5, 2008 If I read your code right, you will end up with forms nested inside a form, which I don't think browsers like so much. Also, I don't think it will make a difference, but it should <form action= not <form value= Quote Link to comment Share on other sites More sharing options...
ThePilots81 Posted February 5, 2008 Author Share Posted February 5, 2008 If I read your code right, you will end up with forms nested inside a form, which I don't think browsers like so much. Also, I don't think it will make a difference, but it should <form action= not <form value= I do end up with forms nested inside a form, but I only have the problem with the first file upload form that gets listed. I changed the form tag to <form action= instead of <form value= but it had no affect. Any other ideas? Quote Link to comment Share on other sites More sharing options...
haku Posted February 6, 2008 Share Posted February 6, 2008 Don't nest your forms. Browsers don't like it. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted February 6, 2008 Share Posted February 6, 2008 Nested forms are invalid HTML. Only the first <form ...> tag is used. 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.