I am trying to parse a current PHP file, with basic data using white space as a delimiator and place that data into a MySQL database.
Here is what I have, can anyone tell me where I am going wrong?
The script connects fine, and actually inserts a record into the database, only problem is, the record is blank.
All files are local on, [url]www.metrosurfing.com/xml/noaa/
[CODE]
<?php
// THIS FILE GRABS LATEST BUOY DATA FROM THE BUOY_DATA.PHP file and SHOVES IT IN A DATABASE
// Database Information
$host = “localhost”;
$user = “metrosurfer”;
$pass = “metropass1961”;
$db = “cid25519_buoy”;
$tbl = “bouy_data”;
$connection = mysql_connect($host, $user, $pass) or die (“Unable to connect!”);
mysql_select_db($db) or die (“Unable to select database!”);
// Open File
$filename = “buoy_data.php”;
$fp = fopen($filename, “r”) or die(“What happend? The file wont open, ****er! $filename”);
// Parse
$count = 0;
$STN = “”;
$YY = “”;
$MM = “”;
$DD = “”;
$hh = “”;
$min = “”;
$WDIR = “”;
$WSPD = “”;
$WVHT = “”;
$DPD = “”;
$APD = “”;
$MWD = “”;
$ATMP = “”;
$WTMP = “”;
while (!feof($fp)){
$string = fgets($fp, 1024);
$string2 = str_replace(“,”, “”, $string);
$count = count(explode(” “, $string2));
$values = explode(” “, $string2);
$STN = $values[0];
$YY = $values[1];
$MM = $values[2];
$DD = $values[3];
$hh = $values[4];
$min = $values[5];
$WDIR = $values[6];
$WSPD = $values[7];
$WVHT = $values[8];
$DPD = $values[9];
$APD = $values[10];
$MWD = $values[11];
$ATMP = $values[12];
$WTMP = $values[13];
}
// insert into databse
mysql_query(“inSERT into bouy_data (STN, YY, MM, DD, hh, min, WDIR, WSPD, WVHT, DPD, APD, MWD, ATMP, WTMP) VALUES(‘$STN’, ‘$YY’, ‘$MM’, ‘$DD’, ‘$hh’, ‘$min’, ‘$WDIR’, ‘$WSPD’, ‘$WVHT’, ‘$DPD’, ‘$APD’, ‘$MWD’, ‘$ATMP’, ‘$WTMP’) “) or die(mysql_error());
echo “shove completed.”
?>
Thank you!!