Jump to content

eco

Members
  • Posts

    19
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Male
  • Location
    Belgium

eco's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thank you for you speedy answer! I was over simplifying the work to be done to avoid useless details to my problem. I'm actually trying to import financial data into a DB, automatically categorise it to re-import into kmymonney2 in a QIF format. What I needed was a prompt if the category can't be found for a specific row (based on a search field). Both your answers were spot on and I think I get a better idea on how this needs to be done now. Thank you both! Many thanks for your help!
  2. Hi, Sorry for the Subject. I have no idea how to write this in one line I'm trying to insert data into a db. I have to cycle through each line in an imported csv file, get prompted for a category, write the data into the db and add a row into the application showing the added data. So I show a page with a form that allows to import the csv file * I cycle through the file - In the loop (as a popup, new form,...), I show the row in the csv, give it a category and write it into the db * Go back to the original form and write the row (with it's category) to the display. How would you do this and using what technology to do it? I'm a poor developer but eager to learn so give me a principle and I'll do my best to implement it. I can't figure out how to leave the loop, say with a popup, and come back to my original page/loop and continue to the next record. Let me know if this is unclear and I'll give it another shot at explaining. Thank you for your help. -eco
  3. You did, thanks a lot for the feedback. I'll browse through the links you gave me and a bit more... a lot to learn Thanks again.
  4. Hi all, I hope this is the right place for this post. I have an application that will write data to a db but if information is missing, the user should be prompted to complete the data before being submitted to the db. The prompt would originally have two combo boxes and a search field (Category, sub-category and search paten). If a cat or sub cat does not exist, by selecting 'new' one should be prompted with a text box to add a row to the drop down. The dropdown are picked up from the db. I was thinking of using a popup for this but I think (still very much a newb so correct me if I'm wrong) a form can only send a single 'item' be it a variable or an array but not two or more. I was just wondering how you would go about prompting a user for more information and then returning to the original screen in the original state it was in. Thanks for any advice.
  5. Hi, I just thought I'd let everyone who helped that I did get it working in the end. I did however compromise a bit and drop my will to use oop and simply put most of the data into the one file. I'll just do some more reading before updating my code to oop. I also had a good browse on the site and found some nice debugging info that helped solve some of my problems. In sort, thank you all for your help. I'll be back soon.
  6. Hi jcbones, Thanks for your post. I'll get working on it this evening when I get back home. I looks to me like all this fits in one file though. I'm trying to send the 'file to a seperate php file with a class->function that will deal with the uploaded file. For example the index.php has a form that loads the file and sends it to csv.php which has a class/function that will put the file into an array and send the array back to index.php something like this: index.php include_once 'csvtest.php'; <form method="post" action="" enctype="multipart/form-data"><label for="file">Filename:</label> <input type="file" name="csvfile" id="csvfile" /><br /> <input type="submit" name="submit" value="Submit" /></form> <?php if ($_FILES ["csvfile"] > 0) { // Send data to function $csv = new csvtest (); $csvarray = $csv->csv2array ( $csvfile ); } foreach($csvarray as $k => $v) { echo '<br />' . $k . ': ' . $v; } csv.php <?php class csvtest { public function csv2array($csvfile) { echo "In csv2array function"; $arrResult = array (); // open the file $handle = fopen ( $csvfile, "r" ); if ($handle) { // put csv file into array while ( ($data = fgetcsv ( $handle, 1000, ";" )) !== FALSE ) { $arrResult [] = $data; } fclose ( $handle ); } else { die ( "<br/><b>Error: Can't open the csv file: $csvfile</b><br/>" ); } //return $arrResult to the index.php file return count($arrResult); } } This is the way I see it but (a) it doesn't work and (b) I'm not sure the design is so good. I'm just trying to move the processing from the main file. Your thoughts? is a good answer too.
  7. Hi AbraCadaver, Thanks for your post. I read the article and tried to find a solution all this evening without success. It seems I still have a bit more to learn before I can do this properly so it's back to the old If you do however have the time for a basic example of a file form being sent to a function (in a seperate file) that would be fab.
  8. Hi all, It's been a while since I was here. It's been a while since I got a chance to get back to php seriously come to think of it. I'm a newb though so be gentle I'm trying to learn the language by writing a basic application that will read from .csv, store in db and write a .qif file to import into my accounting program. Correct me if I'm wrong but I discovered you can't call a function from an html for so I did the following but can't get it to work. I suspect I'm not sending the correct info to the function. Here is what I've come up with: index.php <?php error_reporting ( E_ALL ); include_once 'csvtest.php'; <form method="post" enctype="multipart/form-data"><label for="file">Filename:</label> <input type="file" name="csvfile" id="csvfile" /><br /> <input type="submit" name="submit" value="Submit" /></form> <?php /* * Validate the file */ if ($_FILES ["csvfile"] > 0) { $csvfile = $_FILES ["csvfile"] ["name"]; if ($csvfile != "kbc.csv" && $csvfile != "kt.csv") { die ( "<p>The csv file can only be named <b>kbc.csv</b> or <b>kt.csv</b>.</p>" ); } } else { die ( "<br/><b>Error: Can't find the csv file (" . $_FILES ["csvfile"] ["error"] . ").</b><br/>" ); } // Send data to function $csv = new csvtest (); $csvarray = $csv->csv2array ( $csvfile ); echo "count: " . $csvarray[0]; ?> csvtest.php <?php class csvtest { public function csv2array($csvfile) { echo "In csv2array function"; $arrResult = array (); $handle = fopen ( $csvfile, "r" ); if ($handle) { while ( ($data = fgetcsv ( $handle, 1000, ";" )) !== FALSE ) { $arrResult [] = $data; } fclose ( $handle ); } else { die ( "<br/><b>Error: Can't open the csv file: $csvfile</b><br/>" ); } //return $arrResult; return count($arrResult); } } What am I doing wrong and more importantly, am I going at it the right way? Many thanks for any advice!
  9. ... I did say ../config.php was correct as in... it's in /root/API so ../config.php
  10. Thanks for the clarification... reading about it now
  11. Could you give me a quick example? I don't get what you mean. The file is a restricted file that holds the user and password. This is only accessed by a couple of classes.
  12. OK, will do. I just wanted to avoid using a full path so that I could move my code without having to change all the paths but hey, if that will work, it's worth the extra 5 mins work I'll have a look at the include_dir though! Thanks!
  13. Hi guys, I'm back with another question... I hope I can give back to the forum once I get the hang of PHP I am getting the following warning when I execute my PHP script from any other place than the Class folder Warning: require(../config.php): failed to open stream: No such file or directory in /root/API/Class/API.php on line 30 Fatal error: require(): Failed opening required '../config.php' (include_path='.:/usr/share/php5:/usr/share/php') in /root/API/Class/API.php on line 30 The following is the Class API <?php Class API { public function GetUser($name) { require '../config.php'; [...] } public function ListUsers() { require '../config.php'; [...] } The file is indeed where it's meant to be ie '../config.php' but I admit having trouble figuring out require/require_once, etc. Any help or pointers to documentation are welcome -eco
  14. Thanks a lot, I was about to change it into a string to see if it solved the problem. Great minds think alike Thanks PFMaBiSmAd
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.