Hey guys,
This is my first time working with post data without knowing the index's.
I'm working with an embedded attendance machine that spits out POST data to my php site.
I used wireshark to capture the devices raw post data.
it looks like this and after converting the HEX into ASCI.
321 2011-06-13 11:27:42 0 1
321 2011-06-16 04:06:43 0 2
321 2011-06-16 04:09:11 0 2
The first piece is user, then we have date, time, method and group.
Columns are separated by tab "\t" and row by new line "\n".
I'm also new to working with arrays with raw data like this as I'm not sure how to handle it without an index.
I have had a look at serialize, print_r, or var_dump and all I ever get in my sql database is "Array" or "a:0:{}" and not the actual data or even a part of it.
How can I get this into something when I can put each new line from the sing post array into a separate line in my database?
I was trying to see even just some data and have it put into one field even with no go..
this is as far as I got.
<?
include('config.php');
$conn = mysql_connect($dbserver, $dbuser, $dbpass);
if (!$conn) {
echo "Nope: " . mysql_error();
exit;
}
if (!mysql_select_db($dbname)) {
echo "Nope: " . mysql_error();
exit;
}
$fcontents = $_POST;
for($i=0; $i<sizeof($fcontents); $i++) {
$line = trim($fcontents[$i]);
$arr = explode("\t", $line);
$sql = "insert into data values ('". implode("','", $arr) ."')";
mysql_query($sql);
echo $sql ."<br>\n";
if(mysql_error()) {
echo mysql_error() ."<br>\n";
}
}
?>
I would love count the number of entries then post this to my MYSQL database with the first grouping go into 'user' then 'attdate','atttime','method','group' for the other pieces of data seperated by the "\t"
Thanks!
Looking forward to using the site as a great resource, and I am looking forward to sharing my knowledge. :)
PS. is there a better way to colorify my code for easy readability on this site?
-Chad