gudivada213 Posted April 6, 2009 Share Posted April 6, 2009 Hi Sir, below script...i wrote for updating row into trackroute table from data gpstext file and planroute table. Here gpstext file will change every 5seconds and the row has to insert in trackroute table for each 5 seconds. <?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. Thanks in advance, with sincerely, sravan Quote Link to comment https://forums.phpfreaks.com/topic/152775-insert-row-in-mysql-db-problem/ Share on other sites More sharing options...
Adam Posted April 6, 2009 Share Posted April 6, 2009 What exactly is the problem?? Perhaps skimming over this would get you more help in future. Adam Quote Link to comment https://forums.phpfreaks.com/topic/152775-insert-row-in-mysql-db-problem/#findComment-802252 Share on other sites More sharing options...
revraz Posted April 6, 2009 Share Posted April 6, 2009 echo $query and see what it contains. Quote Link to comment https://forums.phpfreaks.com/topic/152775-insert-row-in-mysql-db-problem/#findComment-802346 Share on other sites More sharing options...
mrMarcus Posted April 6, 2009 Share Posted April 6, 2009 redo your query like this: $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)); depending on your values, check here and ensure your type specifier is matching your argument(s) appropriately when using sprintf .. http://ca3.php.net/manual/en/function.sprintf.php Quote Link to comment https://forums.phpfreaks.com/topic/152775-insert-row-in-mysql-db-problem/#findComment-802376 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.