Another newb

Ok I have a page that displays results from a table. On that page I have a link that will export all the data to excel (this works fine) The issue is that I am trying to create a form on that page that has two date fields and will export information that resides between those two dates. I create the form:

<form action="export2.php" method="POST"> <label for="Begin Date">Begin Date:</label><input type="date" id="begindate" name="begindate"/><label for="End Date">End Date:</label><input type="date" id="enddate" name="enddate"/><input type="submit" value="Export"/> </form> as you can see it process export2.php. The code for export2.php is here:[php]<?PHP
include ‘dbc.php’;

$begindate = $_POST[‘begindate’];
$enddate = $_POST[‘enddate’];

$select = SELECT * FROM form_data WHERE date BETWEEN $begindate AND $enddate;

$export = mysql_query ( $select ) or die ( "Sql error : " . mysql_error( ) );

$fields = mysql_num_fields ( $export );

for ( $i = 0; $i < $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”;
}

header(“Content-type: application/octet-stream”);
header(“Content-Disposition: attachment; filename=form_results_data.xls”);
header(“Pragma: no-cache”);
header(“Expires: 0”);
print “$header\n$data”;

?>[/php] when I press the submit button I get this error: “Parse error: syntax error, unexpected T_STRING in /homepages/2/d208592347/htdocs/websitemorph/cox_form/admin/export2.php on line 7”

I created the date field in phpmyadmin as a date type.

Any help on this would be great and I thank you for your time in advance.

Hello garrick, your $select query is wrong. use below code [php] //use below code $select = "SELECT * FROM form_data WHERE date BETWEEN '".$begindate."' AND '".$enddate."'"; // istead of old sql $select = SELECT * FROM form_data WHERE date BETWEEN $begindate AND $enddate; [/php] I hope this will helpful for you.

Thanks and I appreciate your time, I actually realized my error just before you posted this. :slight_smile:

:slight_smile: :slight_smile: :slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service