Jump to content

mautorrejon

Members
  • Posts

    15
  • Joined

  • Last visited

mautorrejon's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. Here it is...I couldnt find an attachment file options so I just pasted it... /* Result Sets Interface */#ifndef SQL_CRSR# define SQL_CRSR struct sql_cursor { unsigned int curocn; void *ptr1; void *ptr2; unsigned int magic; }; typedef struct sql_cursor sql_cursor; typedef struct sql_cursor SQL_CURSOR;#endif /* SQL_CRSR *//* Thread Safety */typedef void * sql_context;typedef void * SQL_CONTEXT;/* Object support */struct sqltvn{ unsigned char *tvnvsn; unsigned short tvnvsnl; unsigned char *tvnnm; unsigned short tvnnml; unsigned char *tvnsnm; unsigned short tvnsnml;};typedef struct sqltvn sqltvn;struct sqladts{ unsigned int adtvsn; unsigned short adtmode; unsigned short adtnum; sqltvn adttvn[1]; };typedef struct sqladts sqladts;static struct sqladts sqladt = { 1,1,0,};/* Binding to PL/SQL Records */struct sqltdss{ unsigned int tdsvsn; unsigned short tdsnum; unsigned char *tdsval[1]; };typedef struct sqltdss sqltdss;static struct sqltdss sqltds ={ 1, 0,};/* File name & Package Name */struct sqlcxp{ unsigned short fillen; char filnam[8];};static struct sqlcxp sqlfpn ={ 7, "test.pc"};static unsigned int sqlctx = 9995;static struct sqlexd { unsigned int sqlvsn; unsigned int arrsiz; unsigned int iters; unsigned int offset; unsigned short selerr; unsigned short sqlety; unsigned int occurs; short *cud; unsigned char *sqlest; char *stmt; sqladts *sqladtp; sqltdss *sqltdsp; void **sqphsv; unsigned int *sqphsl; int *sqphss; void **sqpind; int *sqpins; unsigned int *sqparm; unsigned int **sqparc; unsigned short *sqpadto; unsigned short *sqptdso; unsigned int sqlcmax; unsigned int sqlcmin; unsigned int sqlcincr; unsigned int sqlctimeout; unsigned int sqlcnowait; int sqfoff; unsigned int sqcmod; unsigned int sqfmod; void *sqhstv[4]; unsigned int sqhstl[4]; int sqhsts[4]; void *sqindv[4]; int sqinds[4]; unsigned int sqharm[4]; unsigned int *sqharc[4]; unsigned short sqadto[4]; unsigned short sqtdso[4];} sqlstm = {12,4};/* SQLLIB Prototypes */extern sqlcxt (/*_ void **, unsigned int *, struct sqlexd *, struct sqlcxp * _*/);extern sqlcx2t(/*_ void **, unsigned int *, struct sqlexd *, struct sqlcxp * _*/);extern sqlbuft(/*_ void **, char * _*/);extern sqlgs2t(/*_ void **, char * _*/);extern sqlorat(/*_ void **, unsigned int *, void * _*/);/* Forms Interface */static int IAPSUCC = 0;static int IAPFAIL = 1403;static int IAPFTL = 535;extern void sqliem(/*_ char *, int * _*/);typedef struct { unsigned short len; unsigned char arr[1]; } VARCHAR;typedef struct { unsigned short len; unsigned char arr[1]; } varchar;/* CUD (Compilation Unit Data) Array */static short sqlcud0[] ={12,4130,1,0,0,5,0,0,1,0,0,27,37,0,0,4,4,0,1,0,1,9,0,0,1,9,0,0,1,10,0,0,1,10,0,0,36,0,0,2,48,0,5,87,0,0,2,2,0,1,0,1,3,0,0,1,3,0,0,59,0,0,3,0,0,29,90,0,0,0,0,0,1,0,74,0,0,4,43,0,5,113,0,0,2,2,0,1,0,1,97,0,0,1,97,0,0,97,0,0,5,0,0,30,117,0,0,0,0,0,1,0,};#include <stdio.h>#include <sqlca.h>#include <string.h>void sqlerror(); /*error message*///void connect(); /*connect*/void printlist(); void Select();void SelectTable();/*void Delete();//void Update();//void Insert();*//* EXEC SQL BEGIN DECLARE SECTION; */ /* varchar user[30]; */ struct { unsigned short len; unsigned char arr[30]; } user; /* varchar pass[30]; */ struct { unsigned short len; unsigned char arr[30]; } pass; char val_1[30], val_2[30]; char table[30]; char v_name[30]; int v_id1; int phone; /* EXEC SQL END DECLARE SECTION; */ /* EXEC SQL INCLUDE SQLCA; */ /* * $Header: sqlca.h,v 1.3 1994/12/12 19:27:27 jbasu Exp $ sqlca.h *//* Copyright © 1985,1986, 1998 by Oracle Corporation. */ /*NAME SQLCA : SQL Communications Area.FUNCTION Contains no code. Oracle fills in the SQLCA with status info during the execution of a SQL stmt.NOTES ************************************************************** *** *** *** This file is SOSD. Porters must change the data types *** *** appropriately on their platform. See notes/pcport.doc *** *** for more information. *** *** *** ************************************************************** If the symbol SQLCA_STORAGE_CLASS is defined, then the SQLCA will be defined to have this storage class. For example: #define SQLCA_STORAGE_CLASS extern will define the SQLCA as an extern. If the symbol SQLCA_INIT is defined, then the SQLCA will be statically initialized. Although this is not necessary in order to use the SQLCA, it is a good pgming practice not to have unitialized variables. However, some C compilers/OS's don't allow automatic variables to be init'd in this manner. Therefore, if you are INCLUDE'ing the SQLCA in a place where it would be an automatic AND your C compiler/OS doesn't allow this style of initialization, then SQLCA_INIT should be left undefined -- all others can define SQLCA_INIT if they wish. If the symbol SQLCA_NONE is defined, then the SQLCA variable will not be defined at all. The symbol SQLCA_NONE should not be defined in source modules that have embedded SQL. However, source modules that have no embedded SQL, but need to manipulate a sqlca struct passed in as a parameter, can set the SQLCA_NONE symbol to avoid creation of an extraneous sqlca variable. MODIFIED lvbcheng 07/31/98 - long to int jbasu 12/12/94 - Bug 217878: note this is an SOSD file losborne 08/11/92 - No sqlca var if SQLCA_NONE macro set Clare 12/06/84 - Ch SQLCA to not be an extern. Clare 10/21/85 - Add initialization. Bradbury 01/05/86 - Only initialize when SQLCA_INIT set Clare 06/12/86 - Add SQLCA_STORAGE_CLASS option.*/ #ifndef SQLCA#define SQLCA 1 struct sqlca { /* ub1 */ char sqlcaid[8]; /* b4 */ int sqlabc; /* b4 */ int sqlcode; struct { /* ub2 */ unsigned short sqlerrml; /* ub1 */ char sqlerrmc[70]; } sqlerrm; /* ub1 */ char sqlerrp[8]; /* b4 */ int sqlerrd[6]; /* ub1 */ char sqlwarn[8]; /* ub1 */ char sqlext[8]; };#ifndef SQLCA_NONE #ifdef SQLCA_STORAGE_CLASSSQLCA_STORAGE_CLASS struct sqlca sqlca#else struct sqlca sqlca#endif #ifdef SQLCA_INIT = { {'S', 'Q', 'L', 'C', 'A', ' ', ' ', ' '}, sizeof(struct sqlca), 0, { 0, {0}}, {'N', 'O', 'T', ' ', 'S', 'E', 'T', ' '}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0} }#endif ;#endif #endif /* end SQLCA */main(){ strcpy(user.arr,"xxxxxxx"); user.len =strlen(user.arr); strcpy(pass.arr,"xxxxxxx"); pass.len = strlen(pass.arr); int listnumber; /* EXEC SQL WHENEVER SQLERROR DO sqlerror(); */ /* EXEC SQL WHENEVER SQLWARNING CONTINUE; */ /* EXEC SQL CONNECT :user IDENTIFIED BY :pass; */ { struct sqlexd sqlstm; sqlstm.sqlvsn = 12; sqlstm.arrsiz = 4; sqlstm.sqladtp = &sqladt; sqlstm.sqltdsp = &sqltds; sqlstm.iters = (unsigned int )10; sqlstm.offset = (unsigned int )5; sqlstm.cud = sqlcud0; sqlstm.sqlest = (unsigned char *)&sqlca; sqlstm.sqlety = (unsigned short)256; sqlstm.occurs = (unsigned int )0; sqlstm.sqhstv[0] = ( void *)&user; sqlstm.sqhstl[0] = (unsigned int )32; sqlstm.sqhsts[0] = ( int )32; sqlstm.sqindv[0] = ( void *)0; sqlstm.sqinds[0] = ( int )0; sqlstm.sqharm[0] = (unsigned int )0; sqlstm.sqadto[0] = (unsigned short )0; sqlstm.sqtdso[0] = (unsigned short )0; sqlstm.sqhstv[1] = ( void *)&pass; sqlstm.sqhstl[1] = (unsigned int )32; sqlstm.sqhsts[1] = ( int )32; sqlstm.sqindv[1] = ( void *)0; sqlstm.sqinds[1] = ( int )0; sqlstm.sqharm[1] = (unsigned int )0; sqlstm.sqadto[1] = (unsigned short )0; sqlstm.sqtdso[1] = (unsigned short )0; sqlstm.sqphsv = sqlstm.sqhstv; sqlstm.sqphsl = sqlstm.sqhstl; sqlstm.sqphss = sqlstm.sqhsts; sqlstm.sqpind = sqlstm.sqindv; sqlstm.sqpins = sqlstm.sqinds; sqlstm.sqparm = sqlstm.sqharm; sqlstm.sqparc = sqlstm.sqharc; sqlstm.sqpadto = sqlstm.sqadto; sqlstm.sqptdso = sqlstm.sqtdso; sqlstm.sqlcmax = (unsigned int )100; sqlstm.sqlcmin = (unsigned int )2; sqlstm.sqlcincr = (unsigned int )1; sqlstm.sqlctimeout = (unsigned int )0; sqlstm.sqlcnowait = (unsigned int )0; sqlcxt((void **)0, &sqlctx, &sqlstm, &sqlfpn); if (sqlca.sqlcode < 0) sqlerror();} //printf ("Record of %i is:", v_id); printlist(); printf("\nSelect from the following services: "); scanf("%d", &listnumber); while (listnumber < 5 && listnumber > 0 ){ switch (listnumber) { case 1: Select(); break; case 2: changeTelephone(); break; case 5: return; break; } printf("\nPlease select the operation number"); scanf("%d",&listnumber); } return;} // end of mainvoid sqlerror(){ printf("Connection Failed"); return; }void printlist(){ printf("\n Options: \n\n"); printf("\n1.Update value in Employee Table \n\n"); printf("\n2.Change Telephone\n\n"); printf("\n5.To quit\n\n"); return; }void changeTelephone() { printf("\n Input EID of Employee:\n"); scanf ("%d", &v_id1); printf ("\n Enter telephone number to change"); scanf ("%d", &phone); printf("%d\n", v_id1); printf("%d\n", phone); /* EXEC SQL update EMPLOYEE set Telephone = :phone where EID = :v_id1; */ { struct sqlexd sqlstm; sqlstm.sqlvsn = 12; sqlstm.arrsiz = 4; sqlstm.sqladtp = &sqladt; sqlstm.sqltdsp = &sqltds; sqlstm.stmt = "update EMPLOYEE set Telephone=:b0 where EID=:b1"; sqlstm.iters = (unsigned int )1; sqlstm.offset = (unsigned int )36; sqlstm.cud = sqlcud0; sqlstm.sqlest = (unsigned char *)&sqlca; sqlstm.sqlety = (unsigned short)256; sqlstm.occurs = (unsigned int )0; sqlstm.sqhstv[0] = ( void *)&phone; sqlstm.sqhstl[0] = (unsigned int )sizeof(int); sqlstm.sqhsts[0] = ( int )0; sqlstm.sqindv[0] = ( void *)0; sqlstm.sqinds[0] = ( int )0; sqlstm.sqharm[0] = (unsigned int )0; sqlstm.sqadto[0] = (unsigned short )0; sqlstm.sqtdso[0] = (unsigned short )0; sqlstm.sqhstv[1] = ( void *)&v_id1; sqlstm.sqhstl[1] = (unsigned int )sizeof(int); sqlstm.sqhsts[1] = ( int )0; sqlstm.sqindv[1] = ( void *)0; sqlstm.sqinds[1] = ( int )0; sqlstm.sqharm[1] = (unsigned int )0; sqlstm.sqadto[1] = (unsigned short )0; sqlstm.sqtdso[1] = (unsigned short )0; sqlstm.sqphsv = sqlstm.sqhstv; sqlstm.sqphsl = sqlstm.sqhstl; sqlstm.sqphss = sqlstm.sqhsts; sqlstm.sqpind = sqlstm.sqindv; sqlstm.sqpins = sqlstm.sqinds; sqlstm.sqparm = sqlstm.sqharm; sqlstm.sqparc = sqlstm.sqharc; sqlstm.sqpadto = sqlstm.sqadto; sqlstm.sqptdso = sqlstm.sqtdso; sqlcxt((void **)0, &sqlctx, &sqlstm, &sqlfpn); if (sqlca.sqlcode < 0) sqlerror();} /* EXEC SQL COMMIT; */ { struct sqlexd sqlstm; sqlstm.sqlvsn = 12; sqlstm.arrsiz = 4; sqlstm.sqladtp = &sqladt; sqlstm.sqltdsp = &sqltds; sqlstm.iters = (unsigned int )1; sqlstm.offset = (unsigned int )59; sqlstm.cud = sqlcud0; sqlstm.sqlest = (unsigned char *)&sqlca; sqlstm.sqlety = (unsigned short)256; sqlstm.occurs = (unsigned int )0; sqlcxt((void **)0, &sqlctx, &sqlstm, &sqlfpn); if (sqlca.sqlcode < 0) sqlerror();} found: printf("\n Record updated"); return; notfound: printf("Record not found in database.\n"); return; }void Select(){ printf("input type to change: "); scanf("%s", &val_1); printf("\n input type to change with: "); scanf("%s", &val_2); /*printf("%d %d ", v_id1, v_id2); //EXEC SQL WHENEVER NOT FOUND GOTO notfound; //found:*/ /* exec sql update COMPANY set TYPE= :val_2 where TYPE= :val_1; */ { struct sqlexd sqlstm; sqlstm.sqlvsn = 12; sqlstm.arrsiz = 4; sqlstm.sqladtp = &sqladt; sqlstm.sqltdsp = &sqltds; sqlstm.stmt = "update COMPANY set TYPE=:b0 where TYPE=:b1"; sqlstm.iters = (unsigned int )1; sqlstm.offset = (unsigned int )74; sqlstm.cud = sqlcud0; sqlstm.sqlest = (unsigned char *)&sqlca; sqlstm.sqlety = (unsigned short)256; sqlstm.occurs = (unsigned int )0; sqlstm.sqhstv[0] = ( void *)val_2; sqlstm.sqhstl[0] = (unsigned int )30; sqlstm.sqhsts[0] = ( int )0; sqlstm.sqindv[0] = ( void *)0; sqlstm.sqinds[0] = ( int )0; sqlstm.sqharm[0] = (unsigned int )0; sqlstm.sqadto[0] = (unsigned short )0; sqlstm.sqtdso[0] = (unsigned short )0; sqlstm.sqhstv[1] = ( void *)val_1; sqlstm.sqhstl[1] = (unsigned int )30; sqlstm.sqhsts[1] = ( int )0; sqlstm.sqindv[1] = ( void *)0; sqlstm.sqinds[1] = ( int )0; sqlstm.sqharm[1] = (unsigned int )0; sqlstm.sqadto[1] = (unsigned short )0; sqlstm.sqtdso[1] = (unsigned short )0; sqlstm.sqphsv = sqlstm.sqhstv; sqlstm.sqphsl = sqlstm.sqhstl; sqlstm.sqphss = sqlstm.sqhsts; sqlstm.sqpind = sqlstm.sqindv; sqlstm.sqpins = sqlstm.sqinds; sqlstm.sqparm = sqlstm.sqharm; sqlstm.sqparc = sqlstm.sqharc; sqlstm.sqpadto = sqlstm.sqadto; sqlstm.sqptdso = sqlstm.sqtdso; sqlcxt((void **)0, &sqlctx, &sqlstm, &sqlfpn); if (sqlca.sqlcode < 0) sqlerror();} if(sqlca.sqlcode == 0){ printf("Update success"); /* exec sql commit work release; */ { struct sqlexd sqlstm; sqlstm.sqlvsn = 12; sqlstm.arrsiz = 4; sqlstm.sqladtp = &sqladt; sqlstm.sqltdsp = &sqltds; sqlstm.iters = (unsigned int )1; sqlstm.offset = (unsigned int )97; sqlstm.cud = sqlcud0; sqlstm.sqlest = (unsigned char *)&sqlca; sqlstm.sqlety = (unsigned short)256; sqlstm.occurs = (unsigned int )0; sqlcxt((void **)0, &sqlctx, &sqlstm, &sqlfpn); if (sqlca.sqlcode < 0) sqlerror();} } else printf ("error message: %s", sqlca.sqlerrm.sqlerrmc); /*printf("\n The following is the information :\n"); //EXEC SQL SELECT NAME, TELEPHONE INTO :v_name, :v_phone // FROM EMPLOYEE // WHERE EID =:v_id; //printf ("\n---%s %s---\n", v_name.arr, v_phone.arr );*/ return; /*notfound: // printf("Record not found in database.\n"); // return; */}
  2. Here I send my entire code, I dont know if that helps #include <stdio.h>#include <sqlca.h>#include <string.h> void sqlerror(); /*error message*///void connect(); /*connect*/void printlist(); void Select();void SelectTable();/*void Delete();//void Update();//void Insert();*/ EXEC SQL BEGIN DECLARE SECTION; varchar user[30];varchar pass[30];char val_1[30], val_2[30];char table[30];char v_name[30];int v_id1;int phone; EXEC SQL END DECLARE SECTION; EXEC SQL INCLUDE SQLCA; main(){ strcpy(user.arr,"xxxxx"); user.len =strlen(user.arr);strcpy(pass.arr,"xxxx"); pass.len = strlen(pass.arr);int listnumber; EXEC SQL WHENEVER SQLERROR DO sqlerror(); EXEC SQL WHENEVER SQLWARNING CONTINUE; EXEC SQL CONNECT :user IDENTIFIED BY :pass; //printf ("Record of %i is:", v_id); printlist();printf("\nSelect from the following services: ");scanf("%d", &listnumber); while (listnumber < 5 && listnumber > 0 ){switch (listnumber) { case 1: Select(); break;case 2: changeTelephone(); break;case 5: return; break; }printf("\nPlease select the operation number"); scanf("%d",&listnumber);} return; } // end of main void sqlerror(){ printf("Connection Failed"); return; } void printlist(){ printf("\n Options: \n\n"); printf("\n1.Update value in Employee Table \n\n");printf("\n2.Change Telephone\n\n"); printf("\n5.To quit\n\n"); return; } void changeTelephone() { printf("\n Input EID of Employee:\n");scanf ("%d", &v_id1);printf ("\n Enter telephone number to change");scanf ("%d", &phone); printf("%d\n", v_id1);printf("%d\n", phone); EXEC SQL update EMPLOYEE set Telephone = :phonewhere EID = :v_id1;EXEC SQL COMMIT; found:printf("\n Record updated");return; notfound:printf("Record not found in database.\n");return; } void Select(){ printf("input type to change: ");scanf("%s", &val_1);printf("\n input type to change with: ");scanf("%s", &val_2); /*printf("%d %d ", v_id1, v_id2); //EXEC SQL WHENEVER NOT FOUND GOTO notfound; //found:*/ exec sql update COMPANY set TYPE= :val_2 where TYPE= :val_1; if(sqlca.sqlcode == 0){printf("Update success");exec sql commit work release;}else printf ("error message: %s", sqlca.sqlerrm.sqlerrmc); /*printf("\n The following is the information :\n"); //EXEC SQL SELECT NAME, TELEPHONE INTO :v_name, :v_phone // FROM EMPLOYEE// WHERE EID =:v_id; //printf ("\n---%s %s---\n", v_name.arr, v_phone.arr );*/ return; /*notfound: // printf("Record not found in database.\n"); // return; */}
  3. yeah I checked in my DB and no changes has been made, even though, my output says it has
  4. Right, but in this case Im not trying to get a value. Im using v_id1 to get the tuple im trying to change and then It's setting attribute Telephone with :phone that the user inputs. This is what my code outputs...I really dont get it. Options: 1.Update value in Employee Table 2.Change Telephone 5.To quit Select from the following services: 2 Input EID of Employee:1234 Enter telephone number to change222333444412347032038138 Record updatedPlease select the operation number
  5. This is my DDL and DML create table EMPLOYEE ( EID int not null, Name char(20) not null, Telephone int null, startdate date not null, PRIMARY KEY (EID));insert into EMPLOYEE values ('1234', 'Jhon Smith', '7032038138', to_date('20020102','YYYYMMDD') );insert into EMPLOYEE values ('4321', 'Jean Rivas', '2022344321', to_date('19980605','YYYYMMDD') );insert into EMPLOYEE values ('2134', 'Richard Lue', '3012314532', to_date('20080409','YYYYMMDD') );insert into EMPLOYEE values ('4231', 'Mark Myers', '5714569876', to_date('19850201','YYYYMMDD') );insert into EMPLOYEE values ('3214', 'Patron Silver', '7034369176', to_date('19991105','YYYYMMDD') );insert into EMPLOYEE values ('2143', 'Lila Cerpes', '2024169976', to_date('19851207','YYYYMMDD') );
  6. Yes Here It is my declaration EXEC SQL BEGIN DECLARE SECTION; varchar user[30];varchar pass[30];char val_1[30], val_2[30];char table[30];char v_name[30];int v_id1;int phone; EXEC SQL END DECLARE SECTION; EXEC SQL INCLUDE SQLCA;
  7. I have this code that is supposed to change the telephone number of a particular tuple, but for some reason it seems like it selects the tuple with EID and then store the Telephone number in my variable phone , instead of changing the telephone number to phone. Thanks printf("\n Input EID of Employee:\n"); scanf ("%d", &v_id1); printf ("\n Enter telephone number to change"); scanf ("%d", &phone); printf("%d", phone); EXEC SQL update EMPLOYEE set Telephone = :phone where EID = :v_id1; EXEC SQL COMMIT; found: printf("\n Record updated"); return; notfound: printf("Record not found in database.\n"); return;
  8. I know how to display all the content andn I also know how many columns my file has so I can make it fit dynamically. I am having trouble creating the table and inputting the header into the table as well as the data itself. This is what I have so far...any help please? <?php //db connections goes here $tableName = "tableToTest"; if ($_FILES["file.csv"]["error"] > 0)echo "Error: " . $_FILES["file.csv"]["error"] . "<br />"; $row = 1;if (($handle = fopen("file.csv", "r")) !== FALSE) {while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {$num = count($data); if ($row==1) { //checks for the headers of the tablefor ($j=0; $j<$num; $j++)$data[$j]."<br/>\n"; while ($j<=$num)mysql_query ("CREATE TABLE ".$table."();"); }//end of IF$row++; } fclose($handle);}?>
  9. My main concern is when I need to upload a csv file to create a entire new table in my DB, without any data definition so later on someone can edit a value within the table. Suppose my DB is full of records of classes, and admins usually edits values, but sometimes they have to upload an entire file which will become a table and all the values in the file would populate the table.
  10. Is there a way of telling the database what type of variable each attribute would hold(i.e. numberic, char, varchar) without going into phpadmin and manipulating it. I guess what I want to accomplish is an interface in which the user only has to upload the csv_file and be able to display it, edit it or delete. My major concern is EDIT. Thanks in advance to anyone
  11. does anyone have a better way to upload a file dynamically into a database(mysql). I know that when doing it from my admin in mysql you have to set the columns and data type, Im trying to make an script to do it dynamically so anyone can upload their file into a database...is that possible?
  12. O.O !!! yes... you have no idea how many times I looked at it...I would look at the rest of the code later and in class now...Thanks a lot!!!!
  13. when I do print_r($_FILES) I get Array( )..this is my compromise code for this particular problem, please let me know what im doing wrong. Thanks handler.php echo '<form method="post" action="upload.php" enctype="multipart/form-data">';echo '<input type="file" name"csv_file" id="csv_file">';echo '<input type="submit" name="submit" value="Upload CSV File">';echo '</form>'; upload.php if ($_FILES["csv_file"]["error"] > 0){echo "Error: " . $_FILES["csv_file"]["error"] . "<br />";}else{echo "Upload: " . $_FILES["csv_file"]["name"] . "<br />";echo "Type: " . $_FILES["csv_file"]["type"] . "<br />";echo "Size: " . ($_FILES["csv_file"]["size"] / 1024) . " Kb<br />";echo "Stored in: " . $_FILES["csv_file"]["tmp_name"];} print_r($_FILE["csv_file"]);//check for file upload if(isset($_FILES['csv_file']) && is_uploaded_file($_FILES['csv_file']['spredSheet'])){ //upload directory $upload_dir = "csv_dir/"; //create file name $file_path = $upload_dir . $_FILES['csv_file']['name']; echo ($_FILES['csv_file']);//echo "asd"; //move uploaded file to upload dir if (!move_uploaded_file($_FILES['csv_file']['tmp_name'], $file_path)) { //error moving upload file echo "Error moving file upload"; } //open the csv file for reading $handle = fopen($file_path, 'r'); //turn off autocommit and delete the product table mysql_query("SET AUTOCOMMIT=0"); mysql_query("BEGIN"); mysql_query("TRUNCATE TABLE $table") or die(mysql_error()); while (($data = fgetcsv($handle, 1000, ',')) !== FALSE) { //Access field data in $data array ex. $name = $data[0]; $quantity = $data[1]; //Use data to insert into db $sql = sprintf("INSERT INTO product_table (product_name, product_quantity) VALUES ('%s',%d)", mysql_real_escape_string($name), $quantity); mysql_query($sql) or (mysql_query("ROLLBACK") and die(mysql_error() . " - $sql")); } //commit the data to the database mysql_query("COMMIT"); mysql_query("SET AUTOCOMMIT=1"); //delete csv file unlink($file_path); }
  14. I get 0 on the page...I tried print_r($_FILES[''csv_file]) and nothing is printed....
  15. Im trying to upload a file to mysql using php and for some reason it doesnt work...could anyone help please..thanks in advance //Here goes the db connection //check for file upload if(isset($_FILES['csv_file']) && is_uploaded_file($_FILES['csv_file']['spredSheet'])){ //upload directory $upload_dir = "csv_dir/"; //create file name $file_path = $upload_dir . $_FILES['csv_file']['name']; echo ($_FILES['csv_file']); //echo "asd"; //move uploaded file to upload dir if (!move_uploaded_file($_FILES['csv_file']['tmp_name'], $file_path)) { //error moving upload file echo "Error moving file upload"; } //open the csv file for reading $handle = fopen($file_path, 'r'); //turn off autocommit and delete the product table mysql_query("SET AUTOCOMMIT=0"); mysql_query("BEGIN"); mysql_query("TRUNCATE TABLE $table") or die(mysql_error()); while (($data = fgetcsv($handle, 1000, ',')) !== FALSE) { //Access field data in $data array ex. $name = $data[0]; $quantity = $data[1]; //Use data to insert into db $sql = sprintf("INSERT INTO product_table (product_name, product_quantity) VALUES ('%s',%d)", mysql_real_escape_string($name), $quantity ); mysql_query($sql) or (mysql_query("ROLLBACK") and die(mysql_error() . " - $sql")); } //commit the data to the database mysql_query("COMMIT"); mysql_query("SET AUTOCOMMIT=1"); //delete csv file unlink($file_path); }
×
×
  • Create New...