473,387 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Upload question answer word file DATA in mysql using php

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. // Set Mysql Variables
  4.  
  5. $db = mysql_connect("localhost","root",""); 
  6. mysql_select_db("testing",$db); 
  7.  
  8.  
  9. $file = "c:/wamp/www/jquery/testdb.csv";
  10. $fp = fopen($file, "r");
  11. $data = fread($fp, filesize($file));
  12. fclose($fp);
  13.  
  14. $output = str_replace("\t|\t", "|", $data);
  15.  
  16. $output = explode("\n", $output);
  17.  
  18. //$language_id = "1";
  19. //$categories_id = 0;
  20.  
  21. foreach($output as $var) {
  22. //$categories_id = $categories_id + 1;
  23.  
  24. $ques = explode("Q", $var);
  25. $op1 = explode("(a)", $var);
  26. $op2 = explode("(b)", $var);
  27. $op3 = explode("(c)", $var);
  28. $op4 = explode("(d)", $var);
  29.  
  30. $res = explode("result",$var);
  31.  
  32. echo $question = trim($ques[0]);
  33. echo $option1 = trim($op1[1]);
  34. echo $option2 = trim($op2[2]);
  35. $option3 = trim($op3[3]);
  36. $option4 = trim($op4[4]);
  37. $result = trim($res[5]);
  38.  
  39. //echo " categories_id: " . $categories_id . " Artikelgroep: " . $Artikelgroep . "<br>";
  40.  
  41. mysql_query("INSERT INTO test (question,option1,option2,option3,option4,result) VALUES('$question','$option1','$option2','$option3','$option4','$result')") or die("Insert failed: " . mysql_error()); 
  42.  
  43. }
  44. echo "Done!";
  45.  
  46.  
  47. ?>
NOTE :- I AM USING THIS SCRIPT BUT THE ALL DATA STORE IN A SINGLE COLUMN I WANT STORE THE DATA IN MULTIPLE COLUMN
Jul 21 '12 #1
1 2300
lyodmichael
75 64KB
what error do you encounter?
do you get any data in your database when you done saving?
Jul 21 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Eric Linders | last post by:
Hi, I have customer contact information in a MySQL DB. The standard stuff: first name, last name, city, state, zip, etc. I'd like to write a PHP script that will take a customer ID range...
1
by: Markusek Peter | last post by:
Hi, I'm using MySQLDriverCS. I've got no problem to store BLOB into database, but I can't get it back(save to file). Problem is with DataTable(returns string:( ) My code: -- DataTable dt = new...
1
by: Devendra | last post by:
How could i insert a pdf file in mysql using PHP and when i access from database it must be open in .html format plz give me reply
2
by: John Smith | last post by:
Hi All, New to this, have the basics, can build a form and such. My problem is I need to be able to open a file on a pc/s on the network, read the data character by character, check to see if a...
1
by: sweet | last post by:
can anybody help me out?what i need to do is -- upload a .doc file to an html format so that the formatted text is not changed.can someone plz provide me with the asp code for this? --...
3
by: vaibhavkansara | last post by:
Hello friends, I am vaibhav I am a new to PHP/MYSQL.I have a problem to uploading a text file into MYSQL using php, and a text file is a tabdelimited file so pleas give me solution as soon as...
0
by: hvinod20 | last post by:
how we can write a program file upload and retrieve from database(sqlserver2000)using asp.net 1.1
0
by: sijugeo | last post by:
Hi, I Have a MS word template field which have certain data fields. I want to populate the data fields using the data retrived from SQL db. How can I do this? Thanks in advance Siju george
4
ddtpmyra
by: ddtpmyra | last post by:
Im having trouble on updating the file inside mysql database using the php. Should I use <form> or im wrong on how I called the variable from previous page? FORM 1 - that accepts the file pointer...
1
by: Joyce Antoun | last post by:
How Can I upload a pdf file to mysql using C sharp?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.