Board index   FAQ   Search  
Register  Login
Board index PHP Your Scripts

Re: database insert row problem

This is where you share YOUR scripts with others

Moderators: macek, egami, gesf

Re: database insert row problem

Postby gudivada213 » Thu Apr 02, 2009 10:31 pm

<?php

// requesting data base details

require("routedb.php");

// Gets data from text file

$myFile = "gpsfile.txt";
$fh = fopen($myFile, 'r');
$gpsdata = fread($fh, filesize($myFile));//u"gps data,pos_lat,pos_long,time,speed, v1
fclose($fh);
$data=explode(",",$gpsdata);
$time=$data[3];//time stamp
$geo_points=$data[1] . "," . $data[2];//latitude/longitude values
$vehicle_id=$data[5];
$speed=$data[4];
$date=date("d/m/y");
$days=date("D");
//Opens a connection to mysql server

$con=mysql_connect($servername,$username,$password);

if(!$con)
{
die("server is not connected " . mysql_error());
}

// Set mysql database

$select_db=mysql_select_db($database,$con);

if(!$select_db)
{
die("$database is not connected:" . mysql_error());
}

//$qry="SELECT plan_id,days,starttime,endtime FROM planroute where vehicle_id=$vehicle_id";
$qry = "SELECT GROUP_CONCAT(plan_id, ',', days, ',', starttime, ',',endtime separator ';') AS plandata FROM planroute WHERE vehicle_id='$vehicle_id';";
$rslt = mysql_query($qry);
if (!$rslt)
{
die('Invalid query: ' . mysql_error());
}

//Iterate through the MySQL results
$row = @mysql_fetch_assoc($rslt);
//$array=$row['plandata'];
//echo $array;
$pd=explode(";",$row['plandata']);
//echo count($pd);

for($i=0;$i<count($pd);$i++)
{
$d=$pd[$i];
$routedata=explode(",",$d);
$daydata=explode(",",$routedata[1]);

for($j=0;$j<count($daydata);$j++)
{
if($days==$daydata[$j])
{
$st=explode(":",$routedata[2]);
$et=explode(":",$routedata[3]);
$gpstime=explode(":",$time);
if(($st[0]<=$gpstime[0])&&($gpstime<=$et[0]))
{
if(($st[1]<=$gpstime[1])&&($gpstime<=$et[1]))
{
if(($st[2]<=$gpstime[2])&&($gpstime<=$et[2]))
{
$plan_id=$route_data[0];
//Insert new row to trackroute with gps data

$query = sprintf("INSERT INTO trackroute " .
"(plan_id, vehicle_id,speed,geo_points, days,date,time) " .
" VALUES ('%s', '%s', '%s','%s',%s,%s,%s);",
mysql_real_escape_string($plan_id),
mysql_real_escape_string($vehicle_id),
mysql_real_escape_string($speed),
mysql_real_escape_string($geo_points),
mysql_real_escape_string($days),
mysql_real_escape_string($date),
mysql_real_escape_string($time));

$result = mysql_query($query);

if (!$result) {
die('Invalid query: ' . mysql_error());
}


}

}
}

}
}

}

?>

Hi, can any one please explain why my code is not inserting data into table.
gudivada213
New php-forum User
New php-forum User
 
Posts: 3
Joined: Mon Mar 30, 2009 12:44 am

Return to Your Scripts

Who is online

Users browsing this forum: No registered users and 0 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.