PHP - Reading From Htm File And Saving In Mysql Table Using Php
Hello
Is it possible to save data from saved htm table from other website in our mysql database system
as I have problem that there is one htm page where i can get data but i want to save it in mysql table. as data is large on htm page
it was hard to copy so i want access it direct from php and save it in mysql table
please guide
awaiting your valuable reply.
Thank in advance
Similar TutorialsFrom what I have so far is that I am reading a text file into a textbox. Now I want to update/append new information to my file(the information may contain HTML/PHP code, text etc.) after I click the save button so the contents can be read on a separate page called "edit.php". Any suggestions? (My first time using PHP on a higher level) The following is written in my editcontent1.php(I'm seperating each content block on my edit.php page into several editcontent(n).php files where n is = 1 to infinity) Here is before the html tags: <?php if ( isset ($_POST ['content']) ) { file_put_contents ('content1.txt', $_POST ['content'] ); } ?> Here is before the html tags: Code: [Select] <form action = "edit.php" method="post"> <textarea name="content" cols="" rows="" wrap="virtual" class="textarea1"> <?php include 'content1.txt'; ?> </textarea> <br /> <input type="submit" value="Save"> </form> I am reading in a table and ordering it by a column labeled "sub" and generating an HTML table. The "sub" column entries are in numerical order (i.e. 1 2 3 4 5 6 7 8 10 11 12 etc. etc.). There are over 100 entries in this table as well. The problem I'm facing is probably obvious to some of you as the display is
1 Obviously I'd like the display to be in numerical order.
What can I do?
Okay I don't mind telling you I am very perplexed on how to read a text file delimited with TAB into a HTML Table using PHP. I don't know where to begin, I have read about 12 examples and get more confused each time. I hope someone can help me. I am looking to read this delimited (TAB) file skipping the first line and reading array's 2,5,6,7,8,9, and 10, then displaying in a HTML Table. Corresponding Headers would be nice. The php file does not work at the present because I am trying to read the array sections by row.
Thank You in advance
Attached Files
ParseText.php 852bytes
3 downloads
JimTest.txt 16.88KB
1 downloads Hey everyone, I posted something similar to this before and thought I had received an answer, but for whatever reason, the script I wrote had inconsistent functionality. It would work sometimes, but not others. At any rate I had to completely revamp the script. Now I'm having the same initial problem with this new script. Basically, what I'm trying to do is get my PHP script to upload a file, insert form info into the MySQL Database Table, and insert the name of the uploaded file into the MySQL Database table as well. I've been able to get everything to work except inserting the name of the uploaded file into the MySQL Database table. I'll show you what I have currently (a stripped down version anyway) then any suggestions you could give would be much appreciated! Please help! I've been working on this for the past month and keep running into issues: Code: [Select] <?php $target_path = "Images/"; $target_path = $target_path . basename($name = $_FILES['pic']['name']); $first_name=$_POST['first_name']; $last_name=$_POST['last_name']; $middle_init=$_POST['middle_init']; mysql_connect("localhost", "My_Username", "My_Password") or die(mysql_error()) ; mysql_select_db("My_Database") or die(mysql_error()) ; if (!$_POST['first_name'] | !$_POST['last_name'] | !$_POST['middle_init']) { header('Location:http://www.mysite.com/error.html'); die(); } $insert = "INSERT INTO image (first_name, last_name, middle_init, name) VALUES ('".$_POST['first_name']."', '".$_POST['last_name']."', '".$_POST['middle_init']."', '".$_POST['name']."')"; $add_member = mysql_query($insert); move_uploaded_file($_FILES['pic']['tmp_name'], $target_path) ?> <HTML> <HEAD> <TITLE>My Site</TITLE> HTML "Confirmation Script" continues on from there. Like I said before, everything works except the name of the uploaded file doesn't get inserted into the MySQL table. Oh...that specific field in the MySQL table is titled "name". Anyway, again, any help you could give would be awesome! Thanks! Hi friends i need a small help in importing csv files into mySQL database table i tried all possible options but i am no where... here is the example for what i am trying to do Mysql DB name = raw Table name is = dump +--------------------+--------------------+ + Account + Bal + +--------------------+--------------------+ + + + +--------------------+--------------------+ CSV Format 50************13, 11095 When they upload the file it should automatically get inserted into appropriate fields any help would be great i tried all possible scripts found in the net could nothing is happening Well, im a n00b for php, and what i need is a php script which will read data from .xml file and write it into .txt file. Can someone help me? Example of .xml file : <?xml version="1.0" encoding="utf-8"?> <tv generator-info-name="NeTXMLTV/1.0.0.0" source-info-url="http://www.net-tv.hr/" source-info-name="NeT TV XMLTV" source-data-url="http://www.net-tv.hr/xmltv/net-pregled-programa-xmltv.xml"> <programme channel="NeT TV" start="20110413063000 +0200" stop="20110413080000 +0200"> <title lang="hr">JUTARNJI EXPRESS</title> <category lang="hr">glazbeno-informativni program</category> <desc lang="hr">Glazbeno informativna emisija sa servisnim informacijama i jutarnjim temperaturama, idealna za jutarnje buđenje uz toplu kavu ili čaj....</desc> </programme> </tv> I need the .txt file to look like this: 201104130630 - 201104130800 JUTARNJI EXPRESS glazbeno-informativni program Glazbeno informativna emisija sa servisnim informacijama i jutarnjim temperaturama, idealna za jutarnje buđenje uz toplu kavu ili čaj.... Can someone please help me? thanks I think this is the right section to post this is in..... Anyway.....I'm building a web site that requires i have functionality to upload a tab delimited file (or some file format that is easiest) via php and insert the data into MYSQL. I've searched for many third party scripts but none seem to work. So I've decided to move to the community to see if someone can give me insight on how i might accomplish this script. I have some third party scripts but I'm not sure if they'd be of any use. Thank you kindly Hi guys, Sorry if this is too dumb, I'm a student yet .. I have: $newEmail = preg_replace($patterns, $replacements, $email); How can I save $newEmail contents into an html file? Thanks a lot!! Am trying to update a table called "budget_request" and also inserting the data of that table into another table called "Budget". The Update works but it is not inserting into the other table. please help me out.. check my code below
<?php $id = $_GET['id']; ?> <?php include('mysql_connect.php'); $q = mysql_query("UPDATE budget_request SET status = 'Approved' WHERE id = '$id'") or die(mysql_error()); // send the details to the budget database $query = mysql_query("SELECT * FROM budget_request WHERE id = '$id' ") or die (mysql_error()); $dat = mysql_fetch_array($query); $department = $dat['department']; $amount = $dat['amount']; // Add the data to the Budget DB $que = (" INSERT INTO budget (id, department, amount, actual) VALUES ( ' ','$department', '$amount', '$amount')" ) or die(mysql_error()); header("Location: add_budget.php"); ?> I have problem how to saving all my record.
when I save I just got 1 record saved in mySQL and it the last record on that table. Here is my code =
<?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO thasil (nrp, nama, pangkat, mgolongan, mtes_fisik, mkemampuan, hasil) VALUES (%s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['nrp'], "int"), GetSQLValueString($_POST['nama'], "text"), GetSQLValueString($_POST['pangkat'], "text"), GetSQLValueString($_POST['mgolongan'], "int"), GetSQLValueString($_POST['mtes_fisik'], "double"), GetSQLValueString($_POST['mkemampuan'], "double"), GetSQLValueString($_POST['hasil'], "double")); mysql_select_db($database_stok, $stok); $Result1 = mysql_query($insertSQL, $stok) or die(mysql_error()); $insertGoTo = ""; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } mysql_select_db($database_stok, $stok); $query_anggotaset = "SELECT * FROM tanggota ORDER BY nrp ASC"; $anggotaset = mysql_query($query_anggotaset, $stok) or die(mysql_error()); $row_anggotaset = mysql_fetch_assoc($anggotaset); $totalRows_anggotaset = mysql_num_rows($anggotaset); mysql_select_db($database_stok, $stok); $query_bobotset = "SELECT * FROM tbobot"; $bobotset = mysql_query($query_bobotset, $stok) or die(mysql_error()); $row_bobotset = mysql_fetch_assoc($bobotset); $totalRows_bobotset = mysql_num_rows($bobotset); $crMax = mysql_query("SELECT min(Golongan) as minK1, max(tes_fisik) as maxK2, max(kemampuan) as maxK3 FROM tanggota"); $max = mysql_fetch_array($crMax); $no=1; ?> <?php include ('header.php') ?> <div id="conten-wrapper"> <div id="conten"> <h1> Normalisasi Anggota Kesamaptaan </h1> <p> <a href="cetak.php"><img src="../images/btn_list.png" height="20"/> >>> Lihat & Cetak Hasil Akhir Perangkingan</a></p> <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1"> <table border="1" cellpadding="3" cellspacing="1"> <tr> <td>no</td> <td>nrp</td> <td>nama</td> <td>pangkat</td> <td>C1 Golongan</td> <td>C2 tes_fisik</td> <td>C3 kemampuan</td> <td>hasil</td> </tr> <?php do { $hasil= round (($max['minK1']/$row_anggotaset['Golongan']*$row_bobotset['golongan']+ $row_anggotaset['tes_fisik']/$max['maxK2']*$row_bobotset['tes_fisik']+ $row_anggotaset['kemampuan']/$max['maxK3']*$row_bobotset['kemampuan']),2) ; ?> <tr> <td><?php echo $no; $no++;?></td> <td><input type="text" name="nrp" value="<?php echo $row_anggotaset['nrp']; ?>" readonly/></td> <td><input type="text" name="nama" value="<?php echo $row_anggotaset['nama']; ?>" readonly/></td> <td><input type="text" name="pangkat" value="<?php echo $row_anggotaset['pangkat']; ?>" size="4" readonly/></td> <td><input type="text" name="mgolongan" value="<?php echo round ($max['minK1']/$row_anggotaset['Golongan'] *$row_bobotset['golongan'],2); ?>" size="2" readonly/></td> <td><input type="text" name="mtes_fisik" value="<?php echo round ($row_anggotaset['tes_fisik']/$max['maxK2'] *$row_bobotset['tes_fisik'],2); ?>" size="2" readonly/></td> <td><input type="text" name="mkemampuan" value="<?php echo round ($row_anggotaset['kemampuan']/$max['maxK3'] *$row_bobotset['kemampuan'],2); ?>" size="3" readonly/></td> <td><input type="text" name="hasil" value="<?php echo $hasil ?>" size="2" readonly/></td> </tr> <?php } while ($row_anggotaset = mysql_fetch_assoc($anggotaset));?> <tr valign="baseline"> <td colspan="8" align="right" nowrap="nowrap"><input type="submit" value="Insert record" /></td> </tr> </table> <input type="hidden" name="MM_insert" value="form1" /> </form> </div> <?php include ('footer.php') ?> </body> </html> <?php mysql_free_result($anggotaset); mysql_free_result($bobotset); ?> I am trying to create a program to get input from user in textarea and save that input into a text file.
But this code is only creating an empty file.
<?php echo <<<_END <form action="form.php" method="post"> <textarea name="textdata" cols="50" rows="20"></textarea> <input type="submit" name="submit" value="CLICK ME"> <input type="hidden" name="submit_check" value="1"> </form> _END; function write(){ $fname="test.txt"; $fh=fopen($fname,'w'); $data=$_POST['textdata']; fwrite($fname,$data); fclose($fh); } if(isset($_POST['submit_check'])){ write(); } ?>please help me. sorry for bad english Edited by mac_gyver, 24 August 2014 - 12:11 PM. code tags please I have figured out far enough to loop through my table and return a list of check boxes that will be matched to a product. My issue now, is i cannot figure out the proper way to loop through them after they are selected and return them as checked/unchecked for the given product. Thought there is some MySQL involved, that part isn't the problem, I know how to insert into a database or update...when the product is selected from a drop down, I need to be able to populate the checkboxes. Here is the code i am using to initially display all of the categories to choose from... <ul class="categories"> <?php $query = "SELECT * FROM products"; $result = mysql_query($query) or die(mysql_error()); while ($row = mysql_fetch_assoc($result)) { $category = $row['category']; $catId = $row['id']; echo "<li><input class='catCheck' type='checkbox' name='p_cat[]' value='$catId' /> $category</li>"; } ?> </ul> Thanks guys.... Hi All, This is my first post on here. I'd really appreciate any help with this, it's driving me mad. I'm trying to create a form to save a image into a mySQL database. I have a website hosted by UK2.net which has a mysql db with a table called gallery(name (varchar 30), size (int), type varchar(30), thePic(mediumBlob)). I have a form with this: Code: [Select] <td><p><label>Pic: </label></td><td><input name="userfile" type="file" id="userfile" /></td></p> Which when submitted actions addImage.php. The code for this looks like this: Code: [Select] <?php $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; $fp = fopen($tmpName, 'r'); $content = fread($fp, filesize($tmpName)); $content = addslashes($content); fclose($fp); if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); } $con = mysql_connect("localhost", "userName", "password") or die(mysql_error()); mysql_select_db("dbName", $con) or die(mysql_error()); $query = "INSERT INTO gallery (name, size, type, thePic) ". "VALUES ('$fileName', '$fileSize', '$fileType', '$content')"; if (!mysql_query($query,$con)) { die('Error: ' . mysql_error()); } echo "<br>File $fileName uploaded<br>"; ?> I get the following error message: Quote Warning: fopen() [function.fopen]: Filename cannot be empty in /home/hiddenje/public_html/addImage.php on line 13 Does anyone know what this is about? I've been on out friend google and a lot of people seem to be pointing to permissions but I can't seem to apply it to my scenario and just can't get it to work. Im a developer by trade, but this is my first step into the...interesting world of PHP and mySQL. Again, I'd appreciate any help with this. I'd love someone to talk me through exactly what I'm missing or doing wrong. Thanks in advance. Can't figure out why the page wont save after clicking save. $KOHDE="index.php?s=admin"; $LOMAKE_W = 400; $TEXTAREA_W = 50; $TEXTAREA_H = 20; $LOMAKE = mysql_real_escape_string($_GET["l"]); $LOMAKE2 = mysql_real_escape_string($_POST["lomake"]); after a few more lines... elseif ($LOMAKE2 == "etusivu"){ #Etusivun muokkaus $teksti = stripslashes($_POST["teksti"]); $f = fopen("etusivu.php", "w"); fwrite($f, $teksti); fclose($f); } elseif ($LOMAKE == "etusivu"){ #Etusivun muokkaus echo "<h1>Edit home page</h1>"; $f = file("etusivu.php"); echo "<form action='$KOHDE' method='post'> <textarea name='teksti' cols='$TEXTAREA_W' rows='$TEXTAREA_H'>"; for ($i = 0; $i < count($f); $i++){ $f[$i] = str_replace("\"", "''", $f[$i]); echo $f[$i]; } echo "</textarea> <input type='hidden' value='etusivu' name='lomake'/> <br><input type='submit' value='Save'/> </form><br/>"; html_ohje(); } I can't see where it has gone wrong. Can anyone help? Hey guys, I need your help on this please. I am working on a php web application. I have a form that gets information for Supplier and his traveling details. The values are stored in arrays. I would like to store supplier details in Supplier table and the travelling details in the Travel table. Here is the code with the comments. <?php if (isset($_VARS['submitSuppliers'])) { //error checking starts here $isError = false; if (empty($_VARS['supplierName'])) { $isError = true; $_VARS['supplierRequest']['supplierName']['errorMessage'] = 'You need to provide a Supplier Name.'; } if (empty($_VARS['address'])) { $isError = true; $_VARS['supplierRequest']['address']['errorMessage'] = 'You need to provide an Address.'; } if (empty($_VARS['travel'])) { $isError = true; $_VARS['supplierRequest']['city']['errorMessage'] = 'You need to provide travelling details.'; } #this checks if there is no error and then proceeds to save form values if (!$isError) { #This function adds the details and Returns the autoincremented Supplier ID $SupId = add_suppliers($_VARS); if ($SupId) { #=== Now here I would like to save the travelling details in the Travel table using the generated supplier id # $travId = add_Travel($_VARS); //==== how do I segregate only travel details from the $_VARS array to store in travel table? REDIRECT('/supplier/index.html', array('confirmationMessage' => 'Your details have been saved.')); }else { notify_admin('supplierjoin.php'); } }else { $_VARS['supplierRequest']['errorMessage'] = "There was a problem with the information you provided. Please check the form and try again."; } } ?> Kindly help. Any comment or feedback is always welcome. Thank you I am trying to use this weeklyReport1Boles.html: Code: [Select] <html> <head> <title>Weekly Report</title> <link rel ="stylesheet" type="text/css" href="sample.css" /> </head> <body> <h1>Weekly Report</h1> <p> <form action = "weeklyReport1Boles.php" method = "post" > <p> <input type = "submit" value = "Display the Report" /> </p> </form> </body> </html> TO PULL data from weeklyDataBoles.txt lines 1-8 1 236.00 2 284.00 3 148.00 4 128.00 5 0.00 6 110.00 7 0.00 8 THE RESULTING WEB PAGE SHOULD BE: Weekly Report TOTAL INCOME FROM PAINT CONTRACTS: $0.00 AVG DAILY INCOME FROM PAINT CONTRACTS: $0.00 NUMBER OF DAYS with NO INCOME: . MY PHP CODE IS: <?php $total = $_POST['total']; $avgDailyIncome = $_POST['avgDailyIncome']; $badDays = $_POST ['badDays']; $paintFile = fopen("weeklyDataBoles.txt","r"); $year = fgets($weeklyDataBoles); $total = 0; for ($count= 1; $count <=7; $count = $count +1) { $nextDay = fgets($weeklyDataBoles); $total = $total + $nextDay; } fclose($weeklyData); $avgDailyIncome = $total/7; print("<p>TOTAL INCOME FROM PAINT CONTRACTS: "); print("$".number_format($total, 2)."</p>"); print("<p>AVG DAILY INCOME FROM PAINT CONTRACTS: "); print("$".number_format($avgDailyIncome, 2)."</p>"); print("<p>NUMBER OF DAYS with NO INCOME: $badDays.</p>"); ?> </body> </html> THE AVERAGES ARE BASED ON ONE WEEK OR SEVEN DAYS, WHY CANT I OPEN THE FILE AND GET THE PROGRAM TO READ IT, I AM A STUDENT AND VERY, VERY, VERY BAD AT THIS, MAKES ME CRAZY CAUSE I REALLY LOVE IT hi i tried to add this to my php file Code: [Select] <?php $xfile = @file('banners.txt', "r"); $random_num = rand (0,count($xfile)-1); $data = explode("::",$xfile[$random_num]); echo $data[1]; ?> i get no output i then tried just including the txt file like include 'banners.txt'; then everything in the txt file opens. and if i use fopen like this Code: [Select] <?php $xfile = fopen ('banners.txt', "r"); $random_num = rand (0,count($xfile)-1); $udata = explode("::",$xfile[$random_num]); echo $udata[1]; ?> i get this error Warning: fopen(banners.txt) [function.fopen]: failed to open stream: No such file or directory in /home/www/public_html/template/folder1/main.php on line 72 where as the txt file exist there anyone could help solve my issue? $tracking_file_location = "../dispatch-manager/logs/tracking_file.txt"; $tracking_file = fopen("$tracking_file_location", "r") or die("Unable to open file!"); $tracking_file_size = filesize("$tracking_file_location"); $tracking_file_text = fread($tracking_file,$tracking_file_size); fclose($tracking_file); I have 4 websites http://www.mercurymagazines.com/pr1/101/101395 http://www.mercurymagazines.com/pr1/169/16000 http://www.mercurymagazines.com/pr1/101/101396 http://www.mercurymagazines.com/pr1/169/16001 I am trying to write a program that will open each webpage one at a time, look for a unique word such as 'FREE' and if it is found the write the URL to a file, if not then no output and the next webpage is opened. I know this word exists only on one of the pages above (http://www.mercurymagazines.com/pr1/101/101396). When http://www.mercurymagazines.com/pr1/101/101396 appears last in the list located in source.txt the programs WORKS. When http://www.mercurymagazines.com/pr1/101/101396 appears in any other position such as first, or second, the program does NOT work. My head is sore from banging against my desk. Any assistance would be appreciated. <?php $file_source = fopen("source.txt", "r"); $file_target = fopen("targets.txt", "w"); while (!feof($file_source) ) { $url = fgets($file_source); echo '<br>'.$url; $raw_text = file_get_contents($url); mb_regex_encoding( "utf-8" ); $words = mb_split( ' +', $raw_text ); foreach ($words as $uniques) { echo $uniques; if ($uniques == 'FREE') { fwrite($file_target, $url); } } } ?> Hello, I am trying to read data from a text file but also adding up the 4th column for example 'name' 'more' '1.00' 'evenmore' so were the 1.00 is I want to add it up is there anyway ? |