Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing one value using 2 forms to multiple php files
    primarykey
    data
    text
    <p>I have a user input for fields 'from' and 'to' which has to be submitted to two different php files which does the export of mysql table to csv file and opens it in a new window for downloading. As I have 2 tables and 2 CSV files to be downloaded by the user, I am having this form to pass values to 2 php files which does the export.</p> <p>Below code has 2 forms and 2 phps, only the first one is working fine. The second form is unable to access the $_POST array.</p> <pre><code> &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;EXPORT INVOICE &lt;/title&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt; &lt;SCRIPT LANGUAGE="JavaScript"&gt; function runscript() { document.f1.submit(); document.f2.submit(); } &lt;/SCRIPT&gt; &lt;/head&gt; &lt;body&gt; &lt;form name="f1" method="post" action="export-tst-with-header.php" target="_blank"&gt; &lt;br&gt; &lt;span class="sty2"&gt;Enter to export From Invoice No.:&lt;/span&gt; &lt;input type="text" size='10' maxlength='10' name="finv"&gt; &lt;span class="sty2"&gt;To Invoice No:&lt;/span&gt;&amp;nbsp; &lt;input type="text" size='10' maxlength='10' name="tinv"&gt; &lt;/form&gt; &lt;form name="f2" method="post" action="export-tst-with-header2.php" target="_blank"&gt; &lt;/form&gt; &lt;input type="button" value="Export" onClick="runscript()"&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Below is the first EXPORT file to convert mysql table to csv file, which is working fine, the second file is also same but only the table exported is different, which is not working:</p> <pre><code> &lt;?php //echo "Exporting file - process"."&lt;br&gt;&lt;br&gt;"; $dbservertype='mysql'; $servername='localhost'; $dbusername='aab'; $dbpassword='aabs'; $dbname='aab'; //////////////////////////////////////// ////// DONOT EDIT BELOW ///////// /////////////////////////////////////// connecttodb($servername,$dbname,$dbusername,$dbpassword); function connecttodb($servername,$dbname,$dbuser,$dbpassword) { global $link; $link=mysql_connect ("$servername","$dbuser","$dbpassword"); if(!$link){die("Could not connect to MySQL");} mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error()); } //////// End of connecting to database //////// $from=$_POST['finv']; $to=$_POST['tinv']; //echo $_POST['action']; //if ($_POST['action'] == 'download') //{ header("Content-type: application/csv"); header("Content-Disposition: attachment; filename=downloadinv.csv"); header("Pragma: no-cache"); header("Expires: 0"); $query = "SELECT * FROM INVHDR WHERE Invno between $from AND $to"; $export = mysql_query ($query ) or die ( "Sql error : " . mysql_error( ) ); $fields = mysql_num_fields ( $export ); for ( $i = 0; $i &lt; $fields; $i++ ) { $header .= mysql_field_name( $export , $i ) . "\t"; } while( $row = mysql_fetch_row( $export ) ) { $line = ''; foreach( $row as $value ) { if ( ( !isset( $value ) ) || ( $value == "" ) ) { $value = "\t"; } else { $value = str_replace( '"' , '""' , $value ); $value = '"' . $value . '"' . "\t"; } $line .= $value; } $data .= trim( $line ) . "\n"; } $data = str_replace( "\r" , "" , $data ); if ( $data == "" ) { $data = "\n(0) Records Found!\n"; } mysql_query("UPDATE INVHDR SET Export=1 WHERE Invno between $from AND $to"); print "$header\n$data"; //} exit(); php?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload