/    Sign up×
Community /Pin to ProfileBookmark

Save an HTML table as CSV

All,

There is a table that I need to import into a MySQL Database. That task seems daunting. Short of that, I’d like a CSV file of the table that I can then upload to my server and import later.

The table I need is behind a user / pass page. I can log in, but do not have access to the scripts, only the HTML.

I have tried doing this with a VBS that had a great number of SendKeys. That has failed and I need another solution.

Can anyone point me in the right direction?

to post a comment
JavaScript

54 Comments(s)

Copy linkTweet thisAlerts:
@Sup3rkirbyApr 03.2014 — If I understand you correctly you need a CSV of a table, but you can only get the table printed out in HTML (as you do not have access to the scripts that read this table)?

I just want to make sure I understand what you are asking before I run off in any direction with my answer.
Copy linkTweet thisAlerts:
@TW79authorApr 03.2014 — Yes, that is exactly correct.
Copy linkTweet thisAlerts:
@Sup3rkirbyApr 03.2014 — I'll be honest in saying I've never done anything like this before. However I'll also be honest in saying I believe what you want is entirely possible. I'll have to sit down and think about the specifics of the script but javascript can be used to loop through a table and place all of the data into a JSON variable. Once you've got the data here then it can be passed to a PHP script that can actually save a .csv file (I do have some code lying around for the PHP to .csv part).

So essentially you'd view the source of the page, copy the table and then paste it into say... a [B]<textarea>[/B] on another page. This page would process the table, push it to PHP and it would get saved as a file.
Copy linkTweet thisAlerts:
@TW79authorApr 03.2014 — Wow... You make it sound so simple!

In my first post, I noted that my final goal is to take the information in this table and put it into a MySQL Database. I don't need the CSV file per se, it was just a medium for importing in MySQL. If we can hash out way to pull the data in Javascript and import into PHP, I won't need the CSV at all.
Copy linkTweet thisAlerts:
@Sup3rkirbyApr 04.2014 — I'm going to start this post by noting that this script is experimental. It's not quite as satisfactory as I'd like (a little bulky. I feel like it could be optimized), however it appears to get the job done. Also, to be fair, I have not seen the HTML tables you wish to export (and then re-import into your database) so this script may need tweaking to fit your specific case.

All of that being said, here's an HTML Table to JSON converter I just made:
[code=html]
<!doctype html>
<html>
<head>
<title>Table to JSON Converter</title>
</head>
<body>

<div id="output"></div>
<div>
Table HTML:<br />
<textarea id="tableHTML" style="width: 640px; height: 480px;"></textarea><br />
<input type="button" value="Convert to JSON" onclick="_TableToJSON(document.getElementById('tableHTML').value)" />
</div>

<script>

var $jsonData = [];
function _TableToJSON($a) {
// We'll copy the table and make it an element on the page
var $colNames = [];
var $tmpTable = document.createElement("div");
$tmpTable.id = "tmpTable";
$tmpTable.innerHTML = $a;
document.body.appendChild($tmpTable);

// Then we hide the table and store it in a js var
var $tableElement = document.getElementById("tmpTable");
$tableElement.style.display = "none";
$tableElement = $tableElement.childNodes[0];
var $tableNodes = [];

// First let's get only the node elements (thead and tbody probably)
for(var $i = 0; $i < $tableElement.childNodes.length; $i++) {
// Let's check to see if it's an element node
if($tableElement.childNodes[$i].nodeType == 1) $tableNodes.push($tableElement.childNodes[$i]); // Save this node!
}

// Now let's loop through our nodes and pull row data
// Yea... it's kind of bulky
for(var $j = 0; $j < $tableNodes.length; $j++) {
var $tmpRow = $tableNodes[$j].childNodes;
var $rowCount = 0;
for(var $k = 0; $k < $tmpRow.length; $k++) {
if($tmpRow[$k].nodeType == 1) {
var $tmpCols = $tmpRow[$k].childNodes;
var $colCount = 0;
for(var $l = 0; $l < $tmpCols.length; $l++) {
if($tmpCols[$l].nodeType == 1) {
if($k == 0) {
$colNames.push($tmpCols[$l].innerHTML);
} else {
if($jsonData[$rowCount-1] == null || $jsonData[$rowCount-1] == undefined) $jsonData[$rowCount-1] = {};
$jsonData[$rowCount-1][$colNames[$colCount]] = $tmpCols[$l].innerHTML;
}
$colCount++;
}
}
$rowCount++;
}
}
}
}
</script>

</body>
</html>
[/code]


And here's a sample table I used to test it with:
[code=html]
<table>
<tr>
<td>Col1</td>
<td>Col2</td>
<td>Col3</td>
<td>Col4</td>
<td>Col5</td>
</tr>
<tr>
<td>Val1</td>
<td>Val2</td>
<td>Val3</td>
<td>Val4</td>
<td>Val5</td>
</tr>
<tr>
<td>Val6</td>
<td>Val7</td>
<td>Val8</td>
<td>Val9</td>
<td>Val10</td>
</tr>
</table>
[/code]


From here I'll look at building a simple PHP script that reads the JSON object and writes it to a database.
Copy linkTweet thisAlerts:
@TcobbApr 04.2014 — You might try something like this. I haven't tested it, but if it works properly it will return an object containing all of the table data. You can use JSON.stringify to put it into JSON format, and PHP can handle that.

[CODE]function doMap(table){ //send the reference of the table as the argument
var obj, i, j, len, jLen, td, hd, val, rows, rowLen;

obj = {"headers": [], "data":[]};
hd = table.getElementsByTagName('th'); //get table header values, if any
len = hd.length;
for(i = 0; i < len; i++){
obj.headers.push(hd[i].innerHTML);
}
rows = table.getElementsByTagName('tr'); //get all the rows in the table
rowLen = rows.length;
for(i = 0; i < rowLen; i++){ //loop throw the rows
obj.data[i] = [];
td = rows[i].getElementsByTagName('td'); //get all the cells in the row
jLen = td.length;
for(j = 0; j < jLen; j++){
obj.data[i].push(td[j].innerHTML); //posh cell data into the array
}
}
return obj;
}[/CODE]
Copy linkTweet thisAlerts:
@TW79authorApr 04.2014 — I'm taking a long weekend from work today. I will test these when I get back. However, in glancing at them, how will either of the two scripts work if I do not have write access to the server on which these pages are located? Perhaps my question wasn't worded correctly. I can log in to the page on the server, but I do not have access to the raw data on the server. All I can see is the table from which I need to pull data. The script would have to log in to the site (or I can set a VBS to do this), and then pull the data on the client-side.
Copy linkTweet thisAlerts:
@Sup3rkirbyApr 04.2014 — In both cases you would essentially log in and view the table data on a webpage. From here you would just view the page's source and copy the [B]<table>[/B] in which this data is in. You can paste it into the [B]<textarea>[/B] in my example and use either my or [B]Tcobb[/B]'s function to convert that HTML [B]<table>[/B] into a structured object. There would be one final step in which this object is passed to a simple PHP script that simply loops through and adds each row to a database (your database).
Copy linkTweet thisAlerts:
@TcobbApr 04.2014 — You actually don't need javascript at all. You can use PHP directly to get the page as a string, and you can parse the table data from there.

$page = file_get_contents("http://somewhere.com");
Copy linkTweet thisAlerts:
@TW79authorApr 04.2014 — Tcobb - Since this page requires user/pass, how do I automate login? My first thought would be to have user/pass saved locally on the computer, then launch the php grabbing the contents of the page I would need. Would you concur, or am I making this too complicated on myself?
Copy linkTweet thisAlerts:
@TcobbApr 04.2014 — Since this page requires user/pass, how do I automate login? My first thought would be to have user/pass saved locally on the computer, then launch the php grabbing the contents of the page I would need. Would you concur, or am I making this too complicated on myself?[/QUOTE]

If you google "automatic login php" you will find a number of scripts for accomplishing this. You might also take a look at the PHP DOMDocument class.
Copy linkTweet thisAlerts:
@TW79authorApr 08.2014 — I'm having quite a bit of trouble automating this. I'm almost unsure of the possibility of achieving this.

I am trying to automate an hourly report on numerous devices scattered throughout the country. Each of these devices is hooked up to a laptop that will be running a small web server (MOWES) and will have internet access. The IP for these devices will remain the same. These devices allow me to log in and view statistics, but I cannot seem to connect to them using the "file_get_contents" command, as I get a 500 error which I assume is because it is looking for the file in the root local host instead of looking on the device. I am putting the "HTTP" in front of the IP address, but alas, it still looks in localhost.

My thought process for creating this hourly report is to log in to the device, pull the table containing the data, export all results into a MySQL database, and have the report run every hour for any stations with stats outside set limits.

I would appreciate some one-on-one help. I have received much help on this forum, but I simply can't seem to get this ball rolling. I have used a combination of VBS, Javascript, PHP, and screaming. Perhaps we can both learn from this process.
Copy linkTweet thisAlerts:
@Sup3rkirbyApr 08.2014 — Just to clarify some things here, you were using [B]CURL[/B] to first 'log in' to a certain page and then attempting to use [B]file_get_contents()[/B] on said page to obtain the data you need. The clarification I need would be that CURL is indeed working on the IP/address you entered, indicating that the script is able to properly connect to the correct location.

Also, not to jump around topics too much (though this is all related to the same end result/goal) you also were setting a variable named [B]$store[/B] which captured the result of the [B]CURL[/B]. I haven't really used [B]CURL[/B] all that much but the return value is essentially whatever the server send back after executing a script and so I wonder is it possible to get your stat page as the result of the [B]CURL[/B], rather than adding an additional step of using [B]file_get_contents()[/B]? I don't know how the server-side of the login system works so I don't know what is actually returned after logging in.

And on a similar note, it was also mentioned by [B]NogDog[/B] that file_get_contents() will not send cookies (which are likely required here) so perhaps you just need to send a second [B]CURL[/B] request. [B]file_get_contents()[/B] is a simple one-liner that can grab the contents of a page but [B]CURL[/B] can still get the page contents as well, just with a few more lines.
Copy linkTweet thisAlerts:
@TW79authorApr 08.2014 — Here is my latest attempt at using CURL to get the login page... Not the page I will eventually need, just the login page. When I run this script, I am getting a 500 server error. It appears to be looking on localhost, not the device to which I am connected. Thoughts on where the error(s) might be?

[code=php]<?php
error_reporting(E_ALL);
ini_set( 'display_errors','1');
$url='http://192.168.69.154';
$ch = curl_init();
$user_agent='Mozilla/5.0 (Windows NT 6.1; rv:8.0) Gecko/20100101 Firefox/8.0'
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch,CURLOPT_CONNECTTIMEOUT,120);
curl_setopt ($ch,CURLOPT_TIMEOUT,120);
curl_setopt ($ch,CURLOPT_MAXREDIRS,10);
curl_setopt ($ch,CURLOPT_COOKIEFILE,"cookie.txt");
curl_setopt ($ch,CURLOPT_COOKIEJAR,"cookie.txt");
echo curl_exec ($ch);
function get_web_page( $url );

curl_close($ch);
echo $ch;

?>[/code]
Copy linkTweet thisAlerts:
@TcobbApr 08.2014 — http://192.168.69.154

I think your problem is here. The 192.168 indicates a local private IP address. From Wikipedia: (private networks)

These addresses are characterized as private because they are not globally delegated, meaning that they are not allocated to any specific organization, and IP packets addressed with them cannot be transmitted through the public Internet. Anyone may use these addresses without approval from a regional Internet registry (RIR). If such a private network needs to connect to the Internet, it must use either a network address translator (NAT) gateway, or a proxy server.[/QUOTE]
Copy linkTweet thisAlerts:
@Sup3rkirbyApr 08.2014 — My first question is about the get_web_page() function. I don't think that's a standard PHP function so I have to ask, do you have the actual function declared somewhere? Every reference to that I found is always a custom function written that simply runs CURL on a given URL. I only ask because if you don't actually have the function delcared somewhere you will get a 500 error (having nothing to do with the URL).

I'm actually not familiar enough with CURL (or file_get_contents() for that matter) to know for sure, but generally if you try to connect to a page that isn't there you shouldn't be getting a 500 error. A 500 error indicates the script on the server encountered an error. The 400 range of errors are related to pages not being found (non-existent, moved or forbidden access). So I almost wonder if the issue isn't connecting to the correct address at all.

One thing I like to do when I have absolutely no clue where an issue in my code is, would be to take out everything except for say... 1 line. Run the script and see if any errors occur. Then I slowly add back in lines (not always 1 line at a time as some code is dependent on other things) and rerun the script. This more or less allows you to see what line (or set of lines) is causing the error. So you might pull everything after $ch = curl_init(); and see if things work. Then add in some of the curl_setopt() lines to see if anything is wrong with those. Then try with the curl_exec() line added in, and so on.
Copy linkTweet thisAlerts:
@TW79authorApr 08.2014 — I dumbed this down a bit, and used a simple INCLUDE command.

[code=php]
<?php
error_reporting(E_ALL);
ini_set( 'display_errors','1');
include('http://192.168.69.154/stalist.cgi');

?>[/code]


Gives me the error:

[CODE]Warning: include(http://192.168.69.154/stalist.cgi): failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found in C:UsersMichelleDesktopmowes_portablewwwwwwgetpagetest.php on line 4 Warning: include(): Failed opening 'http://192.168.69.154/stalist.cgi' for inclusion (include_path='.;C:UsersMichelleDesktopmowes_portablephp5') in C:UsersMichelleDesktopmowes_portablewwwwwwgetpagetest.php on line 4[/CODE]

However, changing the code to:

[code=php]
<?php
error_reporting(E_ALL);
ini_set( 'display_errors','1');
include('http://google.com');

?>
[/code]


Successfully loads google.com. This tells me I might have some error in my config.ini files. I confirmed fopen is enabled, Curl is installed and enabled, and PHP is the server.

What else might be the problem?
Copy linkTweet thisAlerts:
@TW79authorApr 08.2014 — http://192.168.69.154

I think your problem is here. The 192.168 indicates a local private IP address.[/QUOTE]


I agree with you completely, and confirms my findings. I am searching various resources on how to connect to a local IP. Is this even possible? Do you have a recommendation where I can find some help on this?

As a last resort, I can write a VBS to log in and see the table I need, but how do I extract it from that point?
Copy linkTweet thisAlerts:
@Sup3rkirbyApr 08.2014 — Hmm, I mentioned a potential issue with the internal IP on your original 'Auto-Login' topic, but I had assumed you found it wasn't an issue since the topic moved on.

If it is your problem then you will have to use the external IP, and the router would need to be forwarding the proper ports to the internal IP to which you are trying to connect. I don't know how well that plays into your case since this seems to include a number of devices/laptops, but if the target address is always going to be the same then setting up port forwarding should be possible. Essentially in the settings of your router (for the network on which this server is located) you would be forwarding port 80 to your internal IP address (192.168.69.154). Then you would just need to get the external IP (googling "what's my IP" while on that same network will give you your answer) and you could use this in your CURL.

As for extracting your information, assuming you aren't going to use any javascript conversion methods, you can use PHP's DOMDocument to extract the information once you have the HTML of the page you need. If you end up using VBS, I'm not really sure how to bridge this with either the javascript converters provided earlier or DOMDocument.


[B][COLOR="#FF0000"][EDIT][/COLOR][/B]

I don't know why, but all this time I neglected a seemingly obvious potential solution that I'd certainly be more familiar with, AJAX. You could, in theory, use AJAX in the same manor that you are using CURL in PHP. However I guess the first thing that needs to be addressed is the location of your data (which is written to a table after logging in) and the location of the device on which you are attempting to log in from. If these two things are on the same network (same router, VPN, etc.) then AJAX can certainly solve your problems. If they are not on the same network then we venture back to my comments about port forwarding, as this will be the only way to access a network resource remotely. Though I have to assume since you seem to be able to manually go to the page and log in, there has to be some sort of network-related connection.
Copy linkTweet thisAlerts:
@TW79authorApr 08.2014 — I set up port forwarding in the router. 192.168.69.154 forwards to port 80. The script I am using is below. The script seems to hang while "Connecting to Localhost." Are there some other settings I am missing? I am getting the following errors:
[CODE]Warning: include(http://71.40.200.85) [function.include]: failed to open stream: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:xampplitehtdocsindex.php on line 23

Warning: include() [function.include]: Failed opening 'http://71.40.200.85' for inclusion (include_path='.;xampplitephpPEAR') in C:xampplitehtdocsindex.php on line 23

Fatal error: Maximum execution time of 60 seconds exceeded in C:xampplitehtdocsindex.php on line 24[/CODE]


[code=php]<?php

error_reporting(E_ALL);

ini_set( 'display_errors','1');
$url='http://71.40.200.85';
$ch = curl_init();
$user_agent='Mozilla/5.0 (Windows NT 6.1; rv:8.0) Gecko/20100101 Firefox/8.0';
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch,CURLOPT_CONNECTTIMEOUT,120);
curl_setopt ($ch,CURLOPT_TIMEOUT,120);
curl_setopt ($ch,CURLOPT_MAXREDIRS,10);
curl_setopt ($ch,CURLOPT_COOKIEFILE,"cookie.txt");
curl_setopt ($ch,CURLOPT_COOKIEJAR,"cookie.txt");
echo curl_exec ($ch);
function get_web_page( $url ){

curl_close($ch);

echo $ch;

}
include("http://71.40.200.85");
?>[/code]
Copy linkTweet thisAlerts:
@Sup3rkirbyApr 08.2014 — Can you verify that the port forwarding works outside of the script (eg. simply navigating to the IP via browser). I don't know all of the specifics as to how you have things set up but I cannot navigate to that URL which would imply the script isn't failing due to errors really, it's just that you really cannot connect to that address.

[EDIT]

I feel I should also ask, if you take away all of the automatic scripting, how were you able to view this table with information manually? Supposedly you went to a page, logged in and then once logged in were given access to view the table printed in HTML? That being said, and if true, what URL did you use in your browser, and were you on the same network as this server (which contains the necessary data)? Or were you at a remote location on a separate network? I'm just trying to understand if this issue is simpler than it seems to be.
Copy linkTweet thisAlerts:
@TW79authorApr 08.2014 — No, I cannot connect to the URL outside the connected network. Here is how I have set up the port forward.
[CODE]
Forwards
Application Protocol Source Net Port from IP Address Port to Enable
M5 Both 80 192.168.69.154 80 yes
[/CODE]



Using XAMPP on the local machine, are there any settings I need to specify?

If I type in the IP address of the device with the extension of the page containing the data: (192.168.69.154/stalist.cgi) I am taken to a login page. Once logged in, the only information on the page is a table, including a header row, and a submit button.
Copy linkTweet thisAlerts:
@TW79authorApr 08.2014 — The other issue we are going to have is that the other IPs are going to be different for each laptop. The IP of 192.168.69.154 will be the same, but the latptop, and therefore the server, will be different for each machine.
Copy linkTweet thisAlerts:
@TW79authorApr 08.2014 — Correction - the button on the page, once logged in, is a REFRESH button, not a SUBMIT button.
Copy linkTweet thisAlerts:
@Sup3rkirbyApr 08.2014 — Let's take a couple of steps back and realign our paths if we hope to achieve any success here. You have data that requires login to view. You want to take this data and store in a 'master database' on a separate server.

We've been trying to setup a script that connects directly to this data source (the local 192.168.69.154 address?). However you say this data source will be changing, so that even with port forwarding (in an earlier example you'd be forwarding 71.40.200.85 to 192.168.69.154), you would at best have a working system on one laptop and not all?


If everything above is correct then this is really running into a lot of non-coding related issues. Essentially if you have a bunch of local/private data sources and you want to migrate the data elsewhere, the infrastructure of all of these data sources needs to be set up in a way so that you can achieve the proper connectivity first.

But then of course I still don't think I follow the entire situation here. This PHP script you've been trying to run (that automatically logs in and pulls the data), where is it actually located? On the same (local) server as the data source? Or is it on a public/global server somewhere and it's trying to remotely connect to each of these laptops?

Regardless I see a worst case scenario being you have to manually log in, copy the table, paste it into a javascript converter which will convert and push to PHP, which will save it in your database. Obviously the best case scenario here is we work out an automated way of doing this, saving you time and effort overall.
Copy linkTweet thisAlerts:
@TW79authorApr 08.2014 — I agree, this project has come a bit convoluted. I appreciate your help in sorting it all out.

Our company leases communication equipment (telephones) to large work areas. Each telephone is connected to an access point. All access points (20 or so) are connected wirelessly to one central device. This device is connected to a router which is also connected to a small laptop.

The central device reads all the data from the stations and is located at the 192.168.69.154 address. I need to log in to that device and put that data into a central MySQL database that I have set up at one central location. The 69.154 address will not change for any of those central devices. However, the IP address for the laptop will change quite frequently. I might be able to set up a VPN through LogMeIn to make those IPs dynamic.

Automation is almost a necessity as we have 150 or so work areas, and I have been asked to automate this so an hourly report can be generated for any specifications outside a set limit.
Copy linkTweet thisAlerts:
@TW79authorApr 08.2014 — Correction - Use the VPN to make IPs STATIC.... MySQL database is sitting next to me in my office.
Copy linkTweet thisAlerts:
@Sup3rkirbyApr 08.2014 — ...

Our company leases communication equipment (telephones) to large work areas. Each telephone is connected to an access point. All access points (20 or so) are connected wirelessly to one central device. This device is connected to a router which is also connected to a small laptop.

...[/QUOTE]


I'm still not sure I'm on the same page so I just want to make sure I understand this structure.

You have a bunch of individual devices([B]A[/B]). These devices all connect to one central device([B]B[/B]) (which is connected to a router and laptop).

[B]Question)[/B] Now, without any of this fancy scripting stuff, how would you manually connect to get the data for an individual device([B]A[/B])?

I ask in regard to the specifics. I know there is a page you can visit and then log in to. Then you are given a table with some data and a refresh button. But the pieces I'm missing are throwing me off. Is it that you connect a laptop to this individual device([B]A[/B]) and then go to that IP address/page and log in? Or is it that you hop on the laptop that is already connected to the central device([B]B[/B]) and log in using credentials per each individual device([B]A[/B])?
Copy linkTweet thisAlerts:
@TcobbApr 09.2014 — This is all getting rather convoluted. Perhaps you're looking at it from the wrong end. Rather than trying to access the individual units from a myriad of possible configurations, why don't you have the individual machines report at intervals to a central location? If each machine has the ability to transmit data through the internet this seems like it would be a much cleaner approach.
Copy linkTweet thisAlerts:
@TW79authorApr 09.2014 — Kirby - Your synopsis of the layout is correct. The way we are currently seeing the information is by using TeamViewer to log in to each laptop, then using the browser on each laptop to log in to the central device and see the stats, all on one page for all devices connected. As you can imagine, with 150+ locations, it is a full time job in it's own.

Tcobb - The ultimate goal is to have the laptops pull the information and send it to a centralized MySQL database. This is why I'm trying to program a script to log in, and save the HTML information for export into the database.
Copy linkTweet thisAlerts:
@Sup3rkirbyApr 09.2014 — Alright, now that I feel I have a better handle on the structure you have, my next question would be if it's possible for you to set up a webpage that can be executed on each individual laptop (hourly or at any interval necessary)? The webpage would be a typical .html file; I ask because I'm not really familiar with having webpages open up and run automatically.

Ultimately my idea for a potential solution is to have a webpage that runs an AJAX request to log in to the central device and then takes the data returned (a webpage with a table) and parses this data into an organized variable format (JSON). This very same script would then send one final AJAX request to your centralized server, where a PHP file would receive the JSON object and write it to a MySQL database. This should avoid all of the previous issues as these AJAX request will be running directly on the local machines, thus the internal IP will not be an issue.

So if you are certain you can get the .html webpages to run automatically (VBS or perhaps scheduled task on the laptop?) then I can give you a script that will send login data to the central device, request the table, parse the data and then post to a PHP/MySQL script.
Copy linkTweet thisAlerts:
@TW79authorApr 09.2014 — I can set up a scheduled task to open a website in the background. Not an issue there. Just a reminder, the first row of the table we are trying to pull has a header row that will not be needed. Additionally, I will need the computer name, which I can get through VBS if needed. The computer name will need to be one of the items on each row.
Copy linkTweet thisAlerts:
@Sup3rkirbyApr 09.2014 — The header row I assume contains column names? They would be necessary in organizing the data but obviously wouldn't be written as bits of data to the database. And there is no way with javascript (or PHP for that matter) to reliably get the computer name, so this would need to be handled by you somehow. If at all possible I would say pass the computer name into the URL when launching the page (eg. somepage.html?c=COMPUTER_NAME).


Also, for clarification on the login system, where does the login page post to? This is where AJAX will need to submit the username and password.
Copy linkTweet thisAlerts:
@TW79authorApr 09.2014 — I can pass the computer name in the URL. That is not a problem, just tell me how to format the URL.

The login page is: http://192.168.69.154/login.cgi?uri=/stalist.cgi

Here is the source code for that page:

[code=html]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/DTD/loose.dtd">
<html>
<head>
<title>Login</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="0">
<meta http-equiv="Cache-Control" content="no-cache">
<link rel="shortcut icon" href="/140123.1659/favicon.ico" >
<link href="/140123.1659/login.css" rel="stylesheet" type="text/css">
<link href="/140123.1659/style.css" rel="stylesheet" type="text/css">
<link href="/140123.1659/help.css" rel="stylesheet" type="text/css">
<script type="text/javascript" language="javascript" src="jsl10n.cgi"></script>
<script type="text/javascript" src="/140123.1659/js/jquery.js"></script>
<script type="text/javascript" src="/140123.1659/util.js"></script>
<script type="text/javascript" src="/140123.1659/index.js"></script>
<script type="text/javascript" src="/140123.1659/js/jquery.ui.js"></script>
<script type="text/javascript" language="javascript">
//<!--
var globals = {
first_login : false,
postback : false,
fixed : false,
country : ""
};

function onLangChange() {
$("#lang_changed").val("yes");
$("#loginform").submit();
}

function validateForm() {
if ($("#lang_changed").val() == "yes")
return true;

if ($("#country").val() == "0") {
$("#errmsg").text("Please select your country.");
return false;
}

if (!$("#agreed").is(":checked")) {
$("#errmsg").html("To use this product, you must agree to<br/>terms of use.");
return false;
}

return true;
}

$(document).ready(function() {
$("#username").focus();
cache_images([
'main_top.png', 'main.png', 'link.png',
'net.png', '4dv.png', 'srv.png',
'system.png', 'border.gif', 'spectr.gif']);

if (globals.first_login) {
$("#ui_language").change(onLangChange);
$("#loginform").submit(validateForm);
if (!globals.postback && !globals.fixed)
$("#country").val(0);
else
$("#country").val(globals.country);
}
});
//-->
</script>
</head>

<body>
<table border="0" cellpadding="0" cellspacing="0" align="center" class="loginsubtable">
<form enctype="multipart/form-data" id="loginform" method="post" action="/login.cgi">
<tr>
<td valign="top"><img src="/140123.1659/images/airos_logo.png"></td>
<td class="loginsep">
<input type="hidden" name="uri" id="uri" value="/stalist.cgi" />
<table border="0" cellpadding="0" cellspacing="0" class="logintable" align="center">
<tr>
<td colspan="2" align="center">
<div id="errmsg" class="error">

</div>
</td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td><label for="username">Username:</label></td>
<td><input type="text" name="username" id="username" /></td>
</tr>
<tr>
<td><label for="password">Password:</label></td>
<td><input type="password" name="password" id="password" maxlength="8"/></td>
</tr>

<tr>
<td colspan="2">&nbsp;</td>
</tr>
</table>
</td>
</tr>

<tr>
<td colspan="2">

</td>
</tr>
<tr>
<td colspan="2" class="submit" align="right">
<input type="submit" value="Login" />
</td>
</tr>
</form>
</table>
</body>
</html>
[/code]


You are correct, the header row is simply column names. As long as we know (and are able) to omit those from entry into the database.
Copy linkTweet thisAlerts:
@TcobbApr 09.2014 — Just a minor suggestion--store the computer name in local storage. If one isn't there, have the page prompt the user to give it. That way you can send it along with the AJAX data as well without having to mess with the url.
Copy linkTweet thisAlerts:
@Sup3rkirbyApr 09.2014 — [B]Tcobb[/B], I think the ultimate idea is for this to run without any user input (unless I'm mistaken) so a prompt will negate that concept.

Also, I wanted to avoid some 'spammy' post as this next bit will involve some back-and-forth so I can gather the information necessary to make this work with your system, but it seems you don't have PMs enabled, [B]TW79[/B].

In any case I assembled a simple AJAX-based login but I have no clue what the return value will be. This script will place the return value from the AJAX login into a textarea. I simply need to know what this value is (minus any sensitive/private information).
[code=html]
<!doctype html>
<html>
<head>
<title>Auto-Login | Table to JSON | JSON Upload</title>
</head>
<body>

<input type="button" value="Click to Login" onclick="_Login()" />
<textarea id="ajaxResult" style="width: 640px; height: 480px;"></textarea>

<script>
var $u = "USERNAME";
var $p = "PASSWORD";
function _Login() {
$a = new _$AJAX("http://192.168.69.154/login.cgi", "POST", true, "username="+$u+"&password="+$p, function($a, $b) {
if($a != "") _$("ajaxResult").innerHTML = $a;
});
}

// Misc functions for convenience
if(typeof(_$) != "function") function _$($e) { return ($e !== null && $e !== undefined) ? document.getElementById($e) : document; }
function _$AJAX($a, $b, $c, $d, $e) {
var $x = this;
$x.resultData = "";
$x.$oAjax = "";
if(window.XMLHttpRequest) { $x.$oAjax = new XMLHttpRequest();
} else { $x.$oAjax = new ActiveXObject("Microsoft.XMLHTTP"); }
if($x.$oAjax) {
$x.$oAjax.onreadystatechange = function() {
if($x.$oAjax.readyState == 4) {
$x.resultData = $x.$oAjax.responseText;
if($e !== null) $e($x.resultData, $x.$oAjax.status);
}
}
$x.$oAjax.open($b, $a, $c);
$x.$oAjax.setRequestHeader("Content-type","application/x-www-form-urlencoded");
$x.$oAjax.send($d);
}
this._cancel = function(){ this.$oAjax.abort(); };
}
</script>

</body>
</html>
[/code]


I don't really know how the login system is designed to work. If it uses cookies then technically this return value won't matter. The server (central device) should be setting a cookie for the individual once the login is successful. And since this is really a client-side script, once the cookie has been set AJAX should be able to request table page via GET.
Copy linkTweet thisAlerts:
@TW79authorApr 09.2014 — I'm searching for a way to enable PM's, but it doesn't seem obvious to me. Where can I enable them?
Copy linkTweet thisAlerts:
@TW79authorApr 09.2014 — Here is the page after login:

[CODE]

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Associated Stations</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Pragma" content="no-cache">
<link rel="shortcut icon" href="/140123.1659/favicon.ico" >
<link href="/140123.1659/style.css" rel="stylesheet" type="text/css">
</head>


<body class="popup">
<script type="text/javascript" src="/140123.1659/js/jquery.js"></script>
<script type="text/javascript" src="/140123.1659/js/jquery.l10n.js"></script>
<script type="text/javascript" src="/140123.1659/js/jquery.utils.js"></script>
<script type="text/javascript" src="/140123.1659/js/jquery.dataTables.js"></script>
<script type="text/javascript" src="/140123.1659/util.js"></script>
<script type="text/javascript" language="javascript">


var l10n_stalist = {
'day' : "day",
'days' : "days",
'unknown' : "unknown",
'AP-WDS' : "AP-WDS",
'No Associated Stations' : "No Associated Stations",
'Loading, please wait...' : "Loading, please wait...",
'_' : '_'
};


var ab5BeamAngles = [
'<img src="/140123.1659/images/ab5-p39.png" title="+39 degrees">',
'<img src="/140123.1659/images/ab5-p26.png" title="+26 degrees">',
'<img src="/140123.1659/images/ab5-p13.png" title="+13 degrees">',
'<img src="/140123.1659/images/ab5-0.png" title="0 degrees">',
'<img src="/140123.1659/images/ab5-m13.png" title="-13 degrees">',
'<img src="/140123.1659/images/ab5-m26.png" title="-26 degrees">',
'<img src="/140123.1659/images/ab5-m39.png" title="-39 degrees">',
'<img src="/140123.1659/images/ab5-bcast.png" title="bcast">',
];


var sl_global = {
'wlan_iface' : 'ath0',
'autoack' : ('enabled' == 'enabled'),
'ack' : '24',
'distance' : '0',
'airmax_on' : false,
'phased_array' : ('' == '1'),
'beam_angles' : ab5BeamAngles, /* Currently we only have Airbeam-5, need selectivty in future */
'_': '_'
};


</script>
<script type="text/javascript" src="/140123.1659/stalist.js"></script>


<br>
<form action="/stalist.cgi" method="GET">
<table cellspacing="0" cellpadding="0" align="center">
<tr>
<td>
<table id="sta_list" class="listhead dataTables_head" cellspacing="0" cellpadding="0">
<thead>
<tr>
<th>Station MAC&nbsp;&nbsp;&nbsp;</th>
<th>Device Name&nbsp;&nbsp;&nbsp;</th>
<th>Signal / Noise, dBm&nbsp;&nbsp;&nbsp;</th>
<th class="initial_hide">Beam&nbsp;&nbsp;&nbsp;</th>
<th class="initial_hide">Distance&nbsp;&nbsp;&nbsp;</th>
<th>TX/RX, Mbps&nbsp;&nbsp;&nbsp;</th>
<th>CCQ, %&nbsp;&nbsp;&nbsp;</th>
<th>Connection Time&nbsp;&nbsp;&nbsp;</th>
<th>Last IP&nbsp;&nbsp;&nbsp;</th>
<th>Action&nbsp;</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</td>
</tr>
<tr>
<td class="change">
<input type="button" id="_refresh" value="Refresh">
</td>
</tr>
</table>
</form>
</body>
</html>


[/CODE]
Copy linkTweet thisAlerts:
@Sup3rkirbyApr 09.2014 — Alright... there's a lot of parts to this one so bare with me as I don't expect it to work on its first try. Essentially when this page is loaded it will log in to the central device, grab the table data, convert it to a JSON object and then submit it to a PHP script that will write to your database.

You will need to update the username, password and phpScript variables (located at the top of the <script> tag) in order to have this work (or at least attempt to work) properly.
[code=html]
<!doctype html>
<html>
<head>
<title>Auto-Login | Table to JSON | JSON Upload</title>
</head>
<body>

<script>
var $u = "USERNAME";
var $p = "PASSWORD";
var $phpScript = "http://yourserver.com/path/to/php/script.php";
function _Login() {
var $a = new _$AJAX("http://192.168.69.154/login.cgi", "POST", true, "username="+$u+"&password="+$p, function($a, $b) {
if($a != "") _TableToJSON($a);
});
}

var $jsonData = [];
function _TableToJSON($a) {
var $colNames = [];
var $tmpTable = document.createElement("div");
$tmpTable.id = "tmpTable";
$tmpTable.innerHTML = $a;
document.body.appendChild($tmpTable);

var $tableElement = document.getElementById("tmpTable");
$tableElement.style.display = "none";
//$tableElement = $tableElement.childNodes[0];
$tableElement = document.getElementById("sta_list");
var $tableNodes = [];

for(var $i = 0; $i < $tableElement.childNodes.length; $i++) {
if($tableElement.childNodes[$i].nodeType == 1) $tableNodes.push($tableElement.childNodes[$i]);
}

var $headOffset = "";
for(var $j = 0; $j < $tableNodes.length; $j++) {
var $tmpRow = $tableNodes[$j].childNodes;
var $rowCount = 0;
for(var $k = 0; $k < $tmpRow.length; $k++) {
if($tmpRow[$k].nodeType == 1) {
if($headOffset == "") $headOffset = $k;
var $tmpCols = $tmpRow[$k].childNodes;
var $colCount = 0;
for(var $l = 0; $l < $tmpCols.length; $l++) {
if($tmpCols[$l].nodeType == 1) {
if($k == $headOffset && $j == 0) {
$colNames.push($tmpCols[$l].innerHTML.replace(/&nbsp;/g, ""));
} else {
if($jsonData[$rowCount] == null || $jsonData[$rowCount] == undefined) $jsonData[$rowCount] = {};
$jsonData[$rowCount][$colNames[$colCount]] = $tmpCols[$l].innerHTML;
}
$colCount++;
}
}
$rowCount++;
}
}
}
if($jsonData.length > 0) {
_SubmitData();
}
}

function _SubmitData() {
var $a = new _$AJAX($phpScript, "POST", true, "data="+JSON.stringify($jsonData), function($a, $b) {
if($a != "") console.log("I guess all is well...");
});
}

// Misc functions for convenience
if(typeof(_$) != "function") function _$($e) { return ($e !== null && $e !== undefined) ? document.getElementById($e) : document; }
function _$AJAX($a, $b, $c, $d, $e) {
var $x = this;
$x.resultData = "";
$x.$oAjax = "";
if(window.XMLHttpRequest) { $x.$oAjax = new XMLHttpRequest();
} else { $x.$oAjax = new ActiveXObject("Microsoft.XMLHTTP"); }
if($x.$oAjax) {
$x.$oAjax.onreadystatechange = function() {
if($x.$oAjax.readyState == 4) {
$x.resultData = $x.$oAjax.responseText;
if($e !== null) $e($x.resultData, $x.$oAjax.status);
}
}
$x.$oAjax.open($b, $a, $c);
$x.$oAjax.setRequestHeader("Content-type","application/x-www-form-urlencoded");
$x.$oAjax.send($d);
}
this._cancel = function(){ this.$oAjax.abort(); };
}

(function(){ _Login(); })();
</script>

</body>
</html>
[/code]


The final part is the PHP script which will write everything to the database. I don't know anything about your database (column names, etc.) so you will have to do more editing with this script in order to get things working. This script is designed to take the JSON object and loop through it (in the event that you have a table with multiple rows) and write these rows to a database. There are variables (indicated by ALL CAPS, eg. USERNAME) which need to be updated so it can connect to your database. You'll also want to update the column names in the query so it writes to your database properly. This needs to be uploaded to your central server where your MySQL database is located, and of course that address gets entered back into the HTML page above (for the $phpScript variable).
[code=php]
<?php
class dbObj {
function _query($u, $p, $db, $q) {
$dbh = new PDO('mysql:host=localhost;dbname='.$db, $u, $p);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $dbh->prepare($q);
}
}

$dbObj = new dbObj;
$jsonData = (isset($_POST["data"])) ? json_decode($_POST["data"]) : array();

for($i = 0; $i < count($jsonData); $i++) {
$q = $dbObj->_query("USERNAME", "DB_PASSWORD", "DB_NAME", "INSERT INTO TABLE_NAME (station_mac, device_name, signal_noise, beam, distance, tx_rx, ccq, connection_time, last_ip, action) VALUES ('" . $jsonData[$i]["Station MAC"] . "', '" . $jsonData[$i]["Device Name"] . "', '" . $jsonData[$i]["Signal / Noise, dBm"] . "', '" . $jsonData[$i]["Beam"] . "', '" . $jsonData[$i]["Distance"] . "', '" . $jsonData[$i]["TX/RX, Mbps"] . "', '" . $jsonData[$i]["CCQ, %"] . "', '" . $jsonData[$i]["Connection Time"] . "', '" . $jsonData[$i]["Last IP"] . "', '" . $jsonData[$i]["Action"] . "')");
$q->execute();
}

echo "success, maybe?";
?>
[/code]



Lastly, I did not include the code that handles the computer name. That is one of the simpler things to do if you pass it into the URL so we'll worry about that after I can ensure this will work.
Copy linkTweet thisAlerts:
@TW79authorApr 09.2014 — Wow! Thank you for working so hard on this project.

I changed the USERNAME and PASSWORD variables, and also changed the path to the PHP file.

I changed the column names in the PHP so the data will go to the correct column (hopefully).

When I run the script with the edits, I am getting the following error:

[CODE][COLOR=#FF0000][FONT=Consolas]XMLHttpRequest cannot load [URL]http://192.168.69.154/login.cgi[/URL]. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.[/FONT][/COLOR][COLOR=#FF0000][FONT=Consolas] [/FONT][/COLOR][/CODE]

Thoughts?
Copy linkTweet thisAlerts:
@TW79authorApr 09.2014 — I also get this error when running the HTML directly, without localhost:

[COLOR=#FF0000][FONT=Consolas]XMLHttpRequest cannot load [URL]http://192.168.69.154/login.cgi[/URL]. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.[/FONT][/COLOR][COLOR=#FF0000][FONT=Consolas] [/FONT][/COLOR]
Copy linkTweet thisAlerts:
@Sup3rkirbyApr 09.2014 — Foiled by cross-domain scripting...

AJAX is very particular about where it sends request. If the request is to another domain then it's not allowed. And technically this falls into that basket as the IPs (while on the same network) are different.


jQuery supposedly supports cross-domain AJAX request, though I'm not all that familiar with it. I do know that it doesn't allow asynchronous request (meaning the browser sort of... 'pauses' while the request is in process (kind of like waiting on a page to load normally)), but I doubt that'll be an issue.

Give me a bit to plug jQuery AJAX requests into my code instead and then you can give it another try. I'll be a bit busy today but I'll try to have that available within the next few hours.
Copy linkTweet thisAlerts:
@TW79authorApr 09.2014 — This error is on line 1, before anything else is really declared. Is there a simple one-liner type code that would remedy this? I've been searching online for a solution but AJAX is all Greek to me.
Copy linkTweet thisAlerts:
@Sup3rkirbyApr 09.2014 — The error might return line one but that's because the script is set to run on window load. So since the script initiates as soon as the page has loaded the error triggers immediately. Honestly, don't ask me why but errors can often do that. I never really delved into why.

It's actually looking like jQuery can't force cross-domain request if the server doesn't allow it (hence the 'Access-Control-Allow-Origin' header). I don't suppose you have any access to that central device server to where you could have it set up to accept cross domain request? To be fair I'm not entirely sure how to do this (assuming you can't make the change) but I do recall investigating this stuff before and know it won't be too difficult to figure out.


Unfortunately I can't think of a way to get around this issue. I honestly would expect that AJAX would be allowed to preform any request within the same local network, but I can't seem to find anything that indicates how (if it is possible). I do wish I had a remedy because at this point it's really the only thing left to solve for your issue. I'll dig some more to see if there's a way I can get around the cross-domain issues and post back if I figure it out, or come up with another method of getting your overall desired result.
Copy linkTweet thisAlerts:
@TW79authorApr 09.2014 — I have been tinkering with VBS on this issue. I have a script that kinda-sorta works, and what doesn't seem to work is very puzzling. When I get back to the office I will post the script for your review... if you're so inclined. Thank you for being so patient and helpful with this.
Copy linkTweet thisAlerts:
@TcobbApr 10.2014 — If all else fails, you can always do the trick of dynamically adding a script tag to the page which in reality sends data to an active program, as in

[CODE]var head = document.getElementsByTagName('head');
var notAJAX = document.createElement('script');
notAJAX.src = "http://whereEver.com/destination.php&myData=stuffToBeSent";
head.appendChild(notAJAX);[/CODE]


It does have all the limitations of any GET call, but you don't have any "common origin" problems.
Copy linkTweet thisAlerts:
@TW79authorApr 10.2014 — Tcobb - Where in the script does this belong, and what else would I need to edit? It appears I would simply put this at the beginning of the HTML file to run on the local machine and simply edit the notAJAX.src URL. Am I missing anything else here?
Copy linkTweet thisAlerts:
@TW79authorApr 10.2014 — Here is the portion of the VBS that is not working. For some reason, CTRL+A doesn't execute. Any thoughts as to what might be going wrong?

[CODE]
wscript.sleep (10000)Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.SendKeys "admin"
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "xPr3$$"
WshShell.SendKeys "{ENTER}"
wscript.sleep (4000)
WshShell.SendKeys "^{a}"
WshShell.SendKeys "^{c}"
WshShell.SendKeys "^{w}"
[/CODE]
Copy linkTweet thisAlerts:
@TcobbApr 10.2014 — This may be, and probably is, of no value to you whatsoever. I have never really been completely clear on the topology of your setup. I take it that:

  • 1. The information that you want to grab and transmit is funneled through the server on the local network, which does not itself have access to the internet.


  • 2. Your laptop computer has access both to the local network and the internet as well.


  • 3. You have some control over the local server. You could add some javascript to the page which contains the table.


  • --If you have answered no to any of these questions, ignore the rest of this post.

    As far as using dynamically generated script tags to send cross-domain information, here is an example.

    HTML:
    [CODE]<!DOCTYPE HTML>
    <html>
    <head>

    <script>
    var scr;

    function zap(input){
    var head = document.getElementsByTagName('head');
    head = head[0];
    scr = document.createElement('script');
    scr.defer = true;
    scr.src = "http://127.0.0.1/zzz.php" + '?data=' + input;
    head.appendChild(scr);
    }

    window.onload = function(){ //extract data from page and send to server
    var z = document.getElementById('d1');
    zap(z.innerHTML);
    }
    </script>
    </head>
    <body>
    <div id="d1"> FRED </div>
    </body>
    </html>[/CODE]


    Notice it is calling for something other than a static js file. And although the example references a php script on the local computer it can really access it at any domain where the script resides.

    PHP:

    [CODE]<?php
    $str = 'alert("Hello ' . $_GET["data"] . '");';
    echo($str);
    ?>[/CODE]


    The main thing is that the server's response must be some valid javascript. The example here extracts data from the page, sends that to the server, which processes it like any form data, and then sends some javascript back. And there are problems with doing this. Its an imperfect substitute for AJAX, and you do need the server to cooperate to send anything back.
    Copy linkTweet thisAlerts:
    @TW79authorApr 10.2014 — I have fixed the VBS by adding sleep commands after each CTRL+X SendKeys. I now have a CSV of the data from the stalist.cgi page.
    Copy linkTweet thisAlerts:
    @Sup3rkirbyApr 10.2014 — Well it looks like VBS is turning out to be a real hero for your problems.

    Are you able to import the CSV yourself or do you need some scripting for that?
    Copy linkTweet thisAlerts:
    @TW79authorApr 10.2014 — I really appreciate all your help. I'm taking a stab at importing the CSV's and I've already made some progress. The problem I'm going to have is having the script cycle through all the CSV's in a folder for import, then deleting all files after upload.
    Copy linkTweet thisAlerts:
    @TW79authorApr 10.2014 — Now comes the fun part... putting everything where it belongs.

    I have attached the script I am using to import the information from the CSV into the MySQL database. My goals:

    [LIST]
  • [*]Get the file name for entry into the database (I can pass this in the URL if needed)

  • [*]Remove the erroneous three rows at the top of each CSV file (two blank rows and one header row)

  • [*]Have the script cycle through and execute for all CSV's in the directory

  • [*]Delete the CSV's after being imported

  • [/LIST]


    My thought is that the individual laptops will run the script to get the data from stalist.cgi and upload the CSV every hour. Then, half-past every hour, this script will run that imports all CSV files into the database. This gives the computers time to process and upload and ensure I have the most accurate data possible.

    Here is the script I have started with. As you can tell, I am specifying one particular CSV file to be read. I haven't figured out a way to have the script execute for all files. TIMTACULAR is the name of my computer, so you can see that the computer name is used the filename. It makes no difference to be whether the file name, or computer name (via URL) is used.

    [CODE]
    <?php

    $link_id = mysql_connect("localhost", "**", "***") or die("Could not connect."); if(!mysql_select_db("speedtest",$link_id)) die("database was not selected.");


    $file_handle = fopen("resultupload/TIMTACULAR.csv", "r");


    while (($line_of_data = fgetcsv($file_handle, 1000, ",")) !== FALSE) { $line_import_query="INSERT into bridges(MAC,DeviceName,SignalNoiseDBM,Distance,TxRxMbps,CCQ,ConnectionTime,LastIP) values('$line_of_data[0]','$line_of_data[1]','$line_of_data[2]','$line_of_data[3]','$line_of_data[4]','$line_of_data[5]','$line_of_data[6]','$line_of_data[7]')"; mysql_query($line_import_query) or die(mysql_error());
    }




    ?>[/CODE]


    [URL]http://timweitzel.net/wasp/TIMTACULAR.csv[/URL] - Link to the actual CSV file being saved.

    [URL]http://timweitzel.net/wasp/rxbridge.PNG[/URL] - List of Columns in the database
    Copy linkTweet thisAlerts:
    @TW79authorApr 11.2014 — I can see where this portion needs to be in a PHP forum. I will copy it there as to not confuse people. Hopefully this will help other developers along the way.
    ×

    Success!

    Help @TW79 spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.23,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...