Page 1 of 1

problem with "Echo"

Posted: Wed Nov 18, 2009 10:20 am
by steveadams
Hi all

Up until a couple of hours ago I never even dreamed of looking at a php script. However, I found myself needing a script to extract products from an oscommerce database and so I had no choice but to modify an example I found online.

The challenge I am facing is that I am getting a parsing error when I try to run the script and because I dont know what I am doing I really need some help.

Apart from fixing the code I need to do the following:
1) Set the field delimeter to tab.
2) When the user clicks the export button it must give him the option to save the file.

I am using the following code:


<?php
$fieldseparator = ',';
require('includes/application_top.php');
?>

<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
</head>
<body marginwidth="0" marginheight="0" topmargin="25" bottommargin="0" leftmargin="25" rightmargin="0" bgcolor="#FFFFFF">

<?php
$query1 = mysql_query("SELECT products_description.products_name, products_description.products_description, products.products_image, products.products_image_med, products.products_image_lrg, products.products_image_sm_1, products.products_image_xl_1,products.products_image_sm_2,products.products_image_xl_2,products.products_image_sm_3,products.products_image_xl_3,products.products_image_sm_4,products.products_image_xl_4,products.products_image_sm_5,products.products_image_xl_5,products.products_image_sm_6,products.products_image_xl_6,products.products_price,products.products_date_added,products.products_last_modified,products.products_date_available,products.products_weight,products.products_status FROM products Inner Join products_description ON products.products_id = products_description.products_id WHERE products_description.language_id = '1'") or die (mysql_error());
$tabel1 = mysql_fetch_array($query1);

$products_name = $table1['products_name'];
$products_description = $table1['products_description'];
$products_image = $table1['products_image'];
$products_image_med = $table1['products_image_med'];
$products_image_lrg = $table1['products_image_lrg'];
$products_image_sm_1 = $table1['products_image_sm_1'];
$products_image_xl_1 = $table1['products_image_xl_1'];
$products_image_sm_2 = $table1['products_image_sm_2'];
$products_image_xl_2 = $table1['products_image_xl_2'];
$products_image_sm_3 = $table1['products_image_sm_3'];
$products_image_xl_3 = $table1['products_image_xl_3'];
$products_image_sm_4 = $table1['products_image_sm_4'];
$products_image_sm_5 = $table1['products_image_sm_5'];
$products_image_xl_5 = $table1['products_image_xl_5'];
$products_image_sm_6 = $table1['products_image_sm_6'];
$products_image_xl_6 = $table1['products_image_xl_6'];
$products_price = $table1['products_price'];
$products_date_added = $table1['products_date_added'];
$products_last_modified = $table1['products_last_modified'];
$products_date_available = $table1['products_date_available'];
$products_weight = $table1['products_weight'];
$products_status = $table1['products_status'];


// combine all the fields into the variable '$export'
$export = $products_name.$fieldseparator
.$products_description.$fieldseparator
.$products_image.$fieldseparator
.$products_image_med.$fieldseparator
.$products_image_lrg.$fieldseparator
.$products_image_sm_1.$fieldseparator
.$products_image_xl_1.$fieldseparator
.$products_image_sm_2.$fieldseparator
.$products_image_xl_2.$fieldseparator
.$products_image_sm_3.$fieldseparator
.$products_image_xl_3.$fieldseparator
.$products_image_sm_4.$fieldseparator
.$products_image_xl_4.$fieldseparator
.$products_image_sm_5.$fieldseparator
.$products_image_xl_5.$fieldseparator
.$products_image_sm_6.$fieldseparator
.$products_image_xl_6.$fieldseparator
.$products_price.$fieldseparator
.$products_date_added.$fieldseparator
.$products_last_modified.$fieldseparator
.$products_date_available.$fieldseparator
.$products_weight.$fieldseparator
.$products_status.$fieldseparator




echo "<table><tr><td class=main colspan=2><b>Er is een CSV-exportbestand aangemaakt voor:</b><br><br>";
echo "products_description: <b>".$products_description."</b><br>";
echo "products_name": <b>".$products_name."</b><br>;
echo "products_image: <b>".$products_image."</b><br>";
echo "products_image_med: <b>".$products_image_med."</b><br>";
echo "products_image_lrg: <b>".$products_image_lrg."</b><br>";
echo "products_image_sm_1: <b>".$products_image_sm_1."</b><br>";
echo "products_image_xl_1: <b>".$products_image_xl_1."</b><br>";
echo "products_image_sm_1: <b>".$products_image_sm_2."</b><br>";
echo "products_image_xl_1: <b>".$products_image_xl_2."</b><br>";
echo "products_image_sm_1: <b>".$products_image_sm_3."</b><br>";
echo "products_image_xl_1: <b>".$products_image_xl_3."</b><br>";
echo "products_image_sm_1: <b>".$products_image_sm_4."</b><br>";
echo "products_image_xl_1: <b>".$products_image_xl_4."</b><br>";
echo "products_image_sm_1: <b>".$products_image_sm_5."</b><br>";
echo "products_image_xl_1: <b>".$products_image_xl_5."</b><br>";
echo "products_image_sm_1: <b>".$products_image_sm_6."</b><br>";
echo "products_image_xl_1: <b>".$products_image_xl_6."</b><br>";
echo "products_price: <b>".$products_price."</b><br>";
echo "products_date_added: <b>".$products_date_added."</b><br>";
echo "products_last_modified: <b>".$products_last_modified."</b><br>";
echo "products_date_available: <b>".$products_date_available."</b><br>";
echo "products_weight: <b>".$products_weight."</b><br>";
echo "products_status: <b>".$products_status."</b><br>";

echo "<td></tr><BR><center><font face=verdana size=1>osC CSV Export 1.0<HR><BR>";

// toon verzamelde velden in tekstveld (incl. mogelijkheid om de complete inhoud te selecteren
echo "<tr><td><BR><BR><form>
<input type=button value='Selecteer inhoud van het hele veld' onClick='javascript:this.form.scriptsource.focus();this.form.scriptsource.select();'><br>
<textarea name=scriptsource rows=10 cols=50 wrap=ON>".$export."</textarea></form></td></tr></table></html>";
?>

Thanks

Re: problem with "Echo"

Posted: Wed Nov 18, 2009 10:34 am
by jefffan24
Please put your code in the following format:

Code: Select all

Your code here[[b]/[/b]php]

Re: problem with "Echo"

Posted: Wed Nov 18, 2009 10:50 am
by steveadams
I think I am having a very blond moment..

I assume you mean on this site since that wont work in the code?

I cant find a place to modify my post.

Re: problem with "Echo"

Posted: Wed Nov 18, 2009 11:35 am
by Grizzzzzzzzzz
steveadams wrote:I think I am having a very blond moment..

I assume you mean on this site since that wont work in the code?

I cant find a place to modify my post.

Code: Select all

 
 
<?php
$fieldseparator = ',';
require('includes/application_top.php');
?>
 
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
</head>
<body marginwidth="0" marginheight="0" topmargin="25" bottommargin="0" leftmargin="25" rightmargin="0" bgcolor="#FFFFFF">
 
<?php
$query1 = mysql_query("SELECT products_description.products_name, products_description.products_description, products.products_image, products.products_image_med, products.products_image_lrg, products.products_image_sm_1, products.products_image_xl_1,products.products_image_sm_2,products.products_image_xl_2,products.products_image_sm_3,products.products_image_xl_3,products.products_image_sm_4,products.products_image_xl_4,products.products_image_sm_5,products.products_image_xl_5,products.products_image_sm_6,products.products_image_xl_6,products.products_price,products.products_date_added,products.products_last_modified,products.products_date_available,products.products_weight,products.products_status FROM products Inner Join products_description ON products.products_id = products_description.products_id WHERE products_description.language_id = '1'") or die (mysql_error());
$tabel1 = mysql_fetch_array($query1);
 
$products_name = $table1['products_name'];
$products_description = $table1['products_description'];
$products_image = $table1['products_image'];
$products_image_med = $table1['products_image_med'];
$products_image_lrg = $table1['products_image_lrg'];
$products_image_sm_1 = $table1['products_image_sm_1'];
$products_image_xl_1 = $table1['products_image_xl_1'];
$products_image_sm_2 = $table1['products_image_sm_2'];
$products_image_xl_2 = $table1['products_image_xl_2'];
$products_image_sm_3 = $table1['products_image_sm_3'];
$products_image_xl_3 = $table1['products_image_xl_3'];
$products_image_sm_4 = $table1['products_image_sm_4'];
$products_image_sm_5 = $table1['products_image_sm_5'];
$products_image_xl_5 = $table1['products_image_xl_5'];
$products_image_sm_6 = $table1['products_image_sm_6'];
$products_image_xl_6 = $table1['products_image_xl_6'];
$products_price = $table1['products_price'];
$products_date_added = $table1['products_date_added'];
$products_last_modified = $table1['products_last_modified'];
$products_date_available = $table1['products_date_available'];
$products_weight = $table1['products_weight'];
$products_status = $table1['products_status'];
 
 
// combine all the fields into the variable '$export'
$export = $products_name.$fieldseparator
.$products_description.$fieldseparator
.$products_image.$fieldseparator
.$products_image_med.$fieldseparator
.$products_image_lrg.$fieldseparator
.$products_image_sm_1.$fieldseparator
.$products_image_xl_1.$fieldseparator
.$products_image_sm_2.$fieldseparator
.$products_image_xl_2.$fieldseparator
.$products_image_sm_3.$fieldseparator
.$products_image_xl_3.$fieldseparator
.$products_image_sm_4.$fieldseparator
.$products_image_xl_4.$fieldseparator
.$products_image_sm_5.$fieldseparator
.$products_image_xl_5.$fieldseparator
.$products_image_sm_6.$fieldseparator
.$products_image_xl_6.$fieldseparator
.$products_price.$fieldseparator
.$products_date_added.$fieldseparator
.$products_last_modified.$fieldseparator
.$products_date_available.$fieldseparator
.$products_weight.$fieldseparator
.$products_status.$fieldseparator
 
 
 
 
echo "<table><tr><td class=main colspan=2><b>Er is een CSV-exportbestand aangemaakt voor:</b><br><br>";
echo "products_description: <b>".$products_description."</b><br>";
echo "products_name": <b>".$products_name."</b><br>;
echo "products_image: <b>".$products_image."</b><br>";
echo "products_image_med: <b>".$products_image_med."</b><br>";
echo "products_image_lrg: <b>".$products_image_lrg."</b><br>";
echo "products_image_sm_1: <b>".$products_image_sm_1."</b><br>";
echo "products_image_xl_1: <b>".$products_image_xl_1."</b><br>";
echo "products_image_sm_1: <b>".$products_image_sm_2."</b><br>";
echo "products_image_xl_1: <b>".$products_image_xl_2."</b><br>";
echo "products_image_sm_1: <b>".$products_image_sm_3."</b><br>";
echo "products_image_xl_1: <b>".$products_image_xl_3."</b><br>";
echo "products_image_sm_1: <b>".$products_image_sm_4."</b><br>";
echo "products_image_xl_1: <b>".$products_image_xl_4."</b><br>";
echo "products_image_sm_1: <b>".$products_image_sm_5."</b><br>";
echo "products_image_xl_1: <b>".$products_image_xl_5."</b><br>";
echo "products_image_sm_1: <b>".$products_image_sm_6."</b><br>";
echo "products_image_xl_1: <b>".$products_image_xl_6."</b><br>";
echo "products_price: <b>".$products_price."</b><br>";
echo "products_date_added: <b>".$products_date_added."</b><br>";
echo "products_last_modified: <b>".$products_last_modified."</b><br>";
echo "products_date_available: <b>".$products_date_available."</b><br>";
echo "products_weight: <b>".$products_weight."</b><br>";
echo "products_status: <b>".$products_status."</b><br>";
 
echo "<td></tr><BR><center><font face=verdana size=1>osC CSV Export 1.0<HR><BR>";
 
// toon verzamelde velden in tekstveld (incl. mogelijkheid om de complete inhoud te selecteren
echo "<tr><td><BR><BR><form>
<input type=button value='Selecteer inhoud van het hele veld' onClick='javascript&#058;this.form.scriptsource.focus();this.form.scriptsource.select();'><br>
<textarea name=scriptsource rows=10 cols=50 wrap=ON>".$export."</textarea></form></td></tr></table></html>";
?>
 
 

Re: problem with "Echo"

Posted: Wed Nov 18, 2009 11:46 am
by jackpf
You need a semicolon on line 68. Line 75 is also pretty messed up.

Re: problem with "Echo"

Posted: Wed Nov 18, 2009 11:57 am
by qianbc2007
and line 12, TITLE is a variable not defined

Re: problem with "Echo"

Posted: Wed Nov 18, 2009 2:23 pm
by steveadams
Thanks for everybodys help and sorry for wasting your time but I didn't get the result I was looking for. All I want to do is create a tab delimited file to export all data from a mysql query.

I found another script which I modified but there doesn't seem to be any connection to the database. All I get when I run it is an html version of the code.

This is what I've got:

Code: Select all

 
<?php
require('includes/application_top.php');
?>
 
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
//<title><?php echo TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
</head>
<body marginwidth="0" marginheight="0" topmargin="25" bottommargin="0" leftmargin="25" rightmargin="0" bgcolor="#FFFFFF">
 
<?php
 
 
$today = date("YmdHi");
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=".$today."_Backup.txt");
$query = mysql_query("SELECT products_description.products_name, products_description.products_description, products.products_image, products.products_image_med, products.products_image_lrg, products.products_image_sm_1, products.products_image_xl_1,products.products_image_sm_2,products.products_image_xl_2,products.products_image_sm_3,products.products_image_xl_3,products.products_image_sm_4,products.products_image_xl_4,products.products_image_sm_5,products.products_image_xl_5,products.products_image_sm_6,products.products_image_xl_6,products.products_price,products.products_date_added,products.products_last_modified,products.products_date_available,products.products_weight,products.products_status FROM products Inner Join products_description ON products.products_id = products_description.products_id WHERE products_description.language_id =  '1'") or die (mysql_error());
$result = mysql_query($query);
$count = mysql_num_rows($result);
$fields= mysql_num_fields($result);
$data = "";
for ($i=0; $i < $fields; $i++) {
$field = mysql_fetch_field($result, $i);
$data .= $field->name;
$data .= "t";
}
$data .= "n";
while ($row=mysql_fetch_row($result)) {
for($x=0; $x < $fields; $x++) {
$field->name=$row[$x];
$data .= $field->name = $row[$x];
$data .= "t";
}
$data .= "n";
}
echo $data;
?>
 

Re: problem with "Echo"

Posted: Wed Nov 18, 2009 2:44 pm
by steveadams
This is the error that I am getting:

Warning</b>: mysql_num_fields(): supplied argument is not a valid MySQL result resource in <b>/home/macrose1/public_html/macro77.com/admin/osc_export.php

Re: problem with "Echo"

Posted: Thu Nov 19, 2009 3:05 am
by jackpf
Look at your code - where are you connecting to the database?

Re: problem with "Echo"

Posted: Thu Nov 19, 2009 3:28 am
by steveadams
This is my problem. I'm a VB guy and I would normally open the connection first but this php is bugging me. After looking at previous php pages I couldn't see where they openned the connection so I imagined that it was opened elsewhere hence the
"require('includes/application_top.php');" statement.

If you have an example of a page which has a connection statement I would really appreaciate it.

Thanks
Steve

Re: problem with "Echo"

Posted: Thu Nov 19, 2009 3:29 am
by jackpf
http://www.google.co.uk/search?hl=en&so ... =&aq=f&oq=

;)

I think tizag is pretty good: http://www.tizag.com/mysqlTutorial/

I think you're trying to write a script without learning the language. This isn't possible. You need to spend some time understanding how the language works, not try and scrap some code toegther that you've found off the web.

Re: problem with "Echo"

Posted: Thu Nov 19, 2009 5:09 am
by angelicodin
also to add what jackpf linked
http://sqlzoo.net/ has an interactive tutorial. :D

HTH

Re: problem with "Echo"

Posted: Thu Nov 19, 2009 7:53 am
by steveadams
Thanks guys

Yes I know I'm trying to scrape something together in a language that I dont have a clue about. The problem is that I need something urgently and I dont have the funds to pay somebody to do it for me hence the scrambling.

I'm going to those links straight away.
Thanks again
Steve