Jump to content

squishypentagon

Members
  • Posts

    22
  • Joined

  • Last visited

    Never

Everything posted by squishypentagon

  1. here is the full form: <form method="post" enctype="multipart/form-data"> <table border="0" align="center"> <tr> <td>Source CSV file to import:</td> <td rowspan="30" width="10px"> </td> <td><input type="file" name="file_source" id="file_source" class="edt" value="<?=$file_source?>"></td> </tr> <tr> <td>Use CSV header:</td> <td><input type="checkbox" name="use_csv_header" id="use_csv_header" <?=(isset($_POST["use_csv_header"])?"checked":"")?>/></td> </tr> <tr> <td>Separate char:</td> <td><input type="text" name="field_separate_char" id="field_separate_char" class="edt_30" maxlength="1" value="<?=(""!=$_POST["field_separate_char"] ? htmlspecialchars($_POST["field_separate_char"]) : ",")?>"/></td> </tr> <tr> <td>Enclose char:</td> <td><input type="text" name="field_enclose_char" id="field_enclose_char" class="edt_30" maxlength="1" value="<?=(""!=$_POST["field_enclose_char"] ? htmlspecialchars($_POST["field_enclose_char"]) : htmlspecialchars("\""))?>"/></td> </tr> <tr> <td>Escape char:</td> <td><input type="text" name="field_escape_char" id="field_escape_char" class="edt_30" maxlength="1" value="<?=(""!=$_POST["field_escape_char"] ? htmlspecialchars($_POST["field_escape_char"]) : "\\")?>"/></td> </tr> <tr> <td>Encoding:</td> <td> <select name="encoding" id="encoding" class="edt"> <? if(!empty($arr_encodings)) foreach($arr_encodings as $charset=>$description): ?> <option value="<?=$charset?>"<?=($charset == $_POST["encoding"] ? "selected=\"selected\"" : "")?>><?=$description?></option> <? endforeach;?> </select> </td> </tr> <tr> <td colspan="3"> </td> </tr> <tr> <td colspan="3" align="center"><input type="Submit" name="Go" value="Import it" onclick=" var s = document.getElementById('file_source'); if(null != s && '' == s.value) {alert('Define file name'); s.focus(); return false;}"></td> </tr> </table> </form>
  2. I tried that and it didn't work..... does anyone know where i could find a different code for uploading a csv file to write over sql data?
  3. Ok, I have this code that is supposed to upload a csv file and save the contents into a specific sql table. I am getting an error when i hit submit that states the file is empty, meaning the csv file. I am thinking that the file isn't really being targeted i just don't know how to fix it. To start i have a php page with a the form and then i have another php page that is included in the form php page. The functions for submitting the csv info in the text file is located in the include file. here is the code: $csv = new Quick_CSV_import(); $arr_encodings = $csv->get_encodings(); //take possible encodings list $arr_encodings["default"] = "[default database encoding]"; //set a default (when the default database encoding should be used) if(!isset($_POST["encoding"])) $_POST["encoding"] = "default"; //set default encoding for the first page show (no POST vars) if(isset($_POST["Go"]) && ""!=$_POST["Go"]) //form was submitted { $csv->file_name = $HTTP_POST_FILES['file_source']['tmp_name']; //optional parameters $csv->use_csv_header = isset($_POST["use_csv_header"]); $csv->field_separate_char = $_POST["field_separate_char"][0]; $csv->field_enclose_char = $_POST["field_enclose_char"][0]; $csv->field_escape_char = $_POST["field_escape_char"][0]; $csv->encoding = $_POST["encoding"]; //start import now $csv->import(); } else $_POST["use_csv_header"] = 1; ?> <tr> <td>Source CSV file to import:</td> <td rowspan="30" width="10px"> </td> <td><input type="file" name="file_source" id="file_source" class="edt" value="<?=$file_source?>"></td> </tr> and class Quick_CSV_import { var $table_name = "tbl_product"; //where to import to var $file_name; //where to import from var $use_csv_header; //use first line of file OR generated columns names var $field_separate_char; //character to separate fields var $field_enclose_char; //character to enclose fields, which contain separator char into content var $field_escape_char; //char to escape special symbols var $error; //error message var $arr_csv_columns; //array of columns var $table_exists; //flag: does table for import exist var $encoding; //encoding table, used to parse the incoming file. Added in 1.5 version function Quick_CSV_import() { $this->file_name = $file_name; $this->arr_csv_columns = array(); $this->use_csv_header = true; $this->field_separate_char = ","; $this->field_enclose_char = "\""; $this->field_escape_char = "\\"; $this->table_exists = false; } function import() { if($this->table_name=="") $this->table_name = "temp_".date("d_m_Y_H_i_s"); $this->table_exists = false; $this->create_import_table(); if(empty($this->arr_csv_columns)) $this->get_csv_header_fields(); /* change start. Added in 1.5 version */ if("" != $this->encoding && "default" != $this->encoding) $this->set_encoding(); /* change end */ if($this->table_exists) { $sql = "LOAD DATA INFILE '".@mysql_escape_string($this->file_source). "' INTO TABLE `".$this-> table_name. "` FIELDS TERMINATED BY '".@mysql_escape_string($this->field_separate_char). "' OPTIONALLY ENCLOSED BY '".@mysql_escape_string($this->field_enclose_char). "' ESCAPED BY '".@mysql_escape_string($this->field_escape_char). "' ". ($this->use_csv_header ? " IGNORE 1 LINES " : "") ."(`".implode("`,`", $this->arr_csv_columns)."`)"; $res = @mysql_query($sql); $this->error = mysql_error(); } } //returns array of CSV file columns function get_csv_header_fields() { $this->arr_csv_columns = array(); $fpointer = fopen($file_name, "r"); if ($fpointer) { $arr = fgetcsv($fpointer, 10*1024, $this->field_separate_char); if(is_array($arr) && !empty($arr)) { if($this->use_csv_header) { foreach($arr as $val) if(trim($val)!="") $this->arr_csv_columns[] = $val; } else { $i = 1; foreach($arr as $val) if(trim($val)!="") $this->arr_csv_columns[] = "column".$i++; } } unset($arr); fclose($fpointer); } else $this->error = "file cannot be opened: ".(""==$this->file_name ? "[empty]" : @mysql_escape_string($this->file_name)); return $this->arr_csv_columns; } i just can't figure it out. could anyone help me out? the error i get says this: Warning: fopen() [function.fopen]: Filename cannot be empty in /Quick_CSV_import.php on line 83
  4. I'm going to guess that with the amount of views and the lack of response means no one knows what to do.
  5. Ok, I have tried using the code from this link http://answers.yahoo.com/question/index?qid=20100927173625AAmEmiW <?php // Get the name they entered in the form // We'll be naming the file this $file = $_POST['name']; // Get the email from the form $email = $_POST['email']; // We want the file to be a text file right? $ex = ".txt"; // Try to open a file named $file$ex (johndoe.txt for example) // Because this file doesn't exist yet the server creates it $write = fopen("$file$ex","w"); // Now open the file up again but this time save the email in it fwrite($write,$email); // MAKE SURE you close the file!!! fclose($write); // The folder that this script is in on the server is where the file we just made was saved // We can 'rename' it to another folder // The folder on the server we want to move it to $data = "../emails/"; // Now put it all together: This example goes out of the folder we're in and into the folder 'emails' // The new 'name' would be this now (../emails/johndoe.txt): So now the file is moved to where we want for storage rename ("$file","$data$file$ex"); // The script is done, send the user to another page (Just read the address below and you'll get it) exit; ?> unfortunately it doesn't do as i would like. I'm not sure how to get it to save a new file based on a variable on the form page or from one of the fields in the form. What i need is a way for a user to submit the form and it save the data into a uniquely named csv file. I know the code given is for text files, not csv, but that was about all i could find. If there is any help i would greatly appreciate it.
  6. I'm not sure what you are telling me to replace.
  7. ok, well i messed around with the code some more and came up with this. i thought it was working, but no matter how many results i manually put in the database it only says i have 1 result when i run the query: <?php //connection to the database $dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); echo "Connected to MySQL<br />"; //select a database to work with $selected = mysql_select_db("nwacompu_totals",$dbhandle) or die("Could not select examples"); $search = mysql_query("SELECT COUNT(*) FROM totals WHERE timeid ='l1' AND date = '3-16-2011'"); $total_records = mysql_num_rows($search); echo $total_records; ?>
  8. Ok, i have this code that i want to print out the total number of times the defined username appears in my database with the defined date. Right now all it prints out is the echo at the end but with no numbers in the result. I just need help with getting it to display the number. <?php //select a database to work with $selected = mysql_select_db("nwacompu_totals",$dbhandle) or die("Could not select examples"); $username = "bayyari"; $date = "3-16-2011"; $query = "SELECT COUNT(*) FROM totals WHERE date = '$date' AND username = '$username'"; $result = mysql_query($query) or die(mysql_error()); // Print out result while($row = mysql_fetch_array($result)){ echo "There are ". $row['COUNT(username)'] ." ". $row['date'] ." items."; echo "<br />"; echo $result; } ?> what is printed is this There are items. Resource id #2Resource id #3 which makes no sense to me. Any help is very much appreciated.
  9. Thank you thank you thank you! and there is only one instance that the date will be queried so i'm not worried about format because there is only one area it would be pulled. but thank you!
  10. My date is stored as text in the format of m-d-yyyy and i've tried that code and i can't figure out how to pull a specific piece of data, like a specific username in the database. basically i have the user logged in and i want to know how many times their username pops up with the current date
  11. Ok, so far all I have been able to do is to query the database and return each value: $result = mysql_query("SELECT date, username, timeid FROM totals"); while ($row = mysql_fetch_array($result)) { echo $row{'date'}."".$row{'username'}." ".$row{'timeid'}."<br>"; } but i don't want to see each individual entry in the database. All i need is for it to count how many times a specific piece of data shows up for the current date. If anyone could help i would greatly appreciate it.
  12. ok, well i figured it out on my own. all i did was add a table to the cart table for the membership and then deleted the old membership database, and now it works just fine. Thanks for all the help guys!
  13. well, i am getting this error Query : SELECT * FROM `members` WHERE `username`='bayyari' Failed with error: Table 'nwacompu_cart.members' doesn't exist for some reason its looking for nwacompu_cart.members when it should be looking for nwacompu_cart AND nwacompu_members
  14. Well, it did it again, but its linking to this line of code: $fetch_users_data = mysql_fetch_object(mysql_query("SELECT * FROM `members` WHERE `username`='".$user_data."'"));}
  15. Ok, its letting me be logged in and view the shopping cart, but i'm still getting this error: Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /home1/nwacompu/public_html/squishypentagon/cosmotgo/Membership/membersarea.php on line 21 which i'll try and post the exact code, the last time it took out spaces and so the line 19 had changed. <?php session_start();include_once"config.php"; require_once 'library/config.php'; require_once 'library/category-functions.php'; require_once 'library/product-functions.php'; require_once 'library/cart-functions.php'; $_SESSION['shop_return_url'] = $_SERVER['REQUEST_URI']; $catId = (isset($_GET['c']) && $_GET['c'] != '1') ? $_GET['c'] : 0; $pdId = (isset($_GET['p']) && $_GET['p'] != '') ? $_GET['p'] : 0; require_once 'include/header.php'; ob_start(); if(!isset($_SESSION['username']) || !isset($_SESSION['password'])){ header("Location: login.php"); }else{ $user_data = "".$_SESSION['username'].""; $fetch_users_data = mysql_fetch_object(mysql_query("SELECT * FROM `members` WHERE `username`='".$user_data."'")); } ?>
  16. This is all of it, so count down to 19 <?php require_once 'library/config.php'; require_once 'library/category-functions.php'; require_once 'library/product-functions.php'; require_once 'library/cart-functions.php'; $_SESSION['shop_return_url'] = $_SERVER['REQUEST_URI']; $catId = (isset($_GET['c']) && $_GET['c'] != '1') ? $_GET['c'] : 0; $pdId = (isset($_GET['p']) && $_GET['p'] != '') ? $_GET['p'] : 0; require_once 'include/header.php'; ob_start(); session_start();include_once"config.php"; if(!isset($_SESSION['username']) || !isset($_SESSION['password'])){ header("Location: login.php"); }else{ $user_data = "".$_SESSION['username'].""; $fetch_users_data = mysql_fetch_object(mysql_query("SELECT * FROM `members` WHERE `username`='".$user_data."'")); } ?>
  17. I did what you suggested and i get this error, which is not the same as before: Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /home1/nwacompu/public_html/squishypentagon/cosmotgo/Membership/membersarea.php on line 19 and if i don't have the shopping cart code added then it works just fine
  18. I need some help please. I have a project that has a login script that is required before moving to a shopping cart and each use a session. I have a login script that i know works separate of the cart and vice versa. The problem is that when i access the cart i get the session errors and it quits working. So i need help with getting the 2 combined so i can run the cart script while a user is logged in. Here is the code i have. This is the login script session: <? ob_start(); session_start();include_once"config.php"; if(!isset($_SESSION['username']) || !isset($_SESSION['password'])){ header("Location: login.php"); }else{ $user_data = "".$_SESSION['username'].""; $fetch_users_data = mysql_fetch_object(mysql_query("SELECT * FROM `members` WHERE `username`='".$user_data."'")); } ?> This is the script session for the shopping cart: <?php require_once 'library/config.php'; require_once 'library/category-functions.php'; require_once 'library/product-functions.php'; require_once 'library/cart-functions.php'; $_SESSION['shop_return_url'] = $_SERVER['REQUEST_URI']; $catId = (isset($_GET['c']) && $_GET['c'] != '1') ? $_GET['c'] : 0; $pdId = (isset($_GET['p']) && $_GET['p'] != '') ? $_GET['p'] : 0; require_once 'include/header.php'; ?> and any help is very much appreciated.
  19. I really need some guidance. I don't necessarily need to have someone do it, but stepping me through it would be ok. I just havent done much with php if statements so yeah.
  20. I have a pretty complicated script i'm trying to work on but i'm not having much luck. Basically what needs to happen is i need part of my script to check a database and count 2 different sets of data for the current date, then if both conditions are true then submit the users name, current date, and a time id to the database it checks, and then submit the form data to a text file. i'll try and map it out. check database for how many times the username appears for current date if it is less than 3 move to next validation if it is false, give error message check database for how many times the time id appears for current date if it is less than 30 move to next section if it is false, give error message send username, timestamp (of clients computer), and time id to the 'totals' database and send form data to text file. So.... thats it in a nutshell. I'm going to have to go into my 'cart' page and edit in a row to have the order#, username, timestamp, and time id before the rest of the order details
×
×
  • 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.