MySQL and PHP parsing strange string
Im exporting tables from Android(SQLite) to MYSQL using PHP to communicate
with the server (I use XAMPP as tool).
I have a table in sqlite with a string field(named "Start"), which tells
me the current time in a format that I specially designed. A example is:
0:03:14 -- 2013/8/12. I give this information to the server using HttpPost
in Android.
Here comes the problem. I create the table for mysql using "varchar(50)"
type for "Start" field for example. When Im inserting into the table, I
got the next message using JSON:
08-12 16:51:25.383: D/MYSQL(26304): jsonResult {"phpError":"You have an
error in your SQL syntax; check the manual that corresponds to your MySQL
server version for the right syntax to use near ':36:12 -- 2013\/8\/6,
\r\n\t18:36:17 -- 2013\/7\/6, 30, 57)' at line
2","Success":0,"Message":"Oops! Couldnt upload data","Start":"18:36:12 --
2013\/8\/6"}
As you see, the original start string is 18:36:12, however, in the error
message it appears "to use near ':36:12" so it seems it has some problem
to "parse" the string (?). Anyone knows whats happening? Should I use
different type for this field?
This is my PHP file:
<?php
$response = array();
require_once __DIR__ . '/db_connect.php';
$db = new DB_CONNECT();
$sql1 = "CREATE TABLE IF NOT EXISTS mobile_metadata(ID int, Acc int,
Mag int, Gyr int, Temperature int, Grav int,
Light int, LinAcc int, Pressure int, Proximity int, Humidity int,
RotVec int, Format varchar(50), Start varchar(50),
Finish varchar(50), First int, Last int);";
$result1 = mysql_query($sql1);
//Data succesfully created/was already created
if($result1){
$id = $_POST['id']; $acc = $_POST['Acc']; $mag = $_POST['Mag'];
$gyr = $_POST['Gyr']; $temperature = $_POST['Temperature']; $grav
= $_POST['Grav'];
$light = $_POST['Light']; $linAcc = $_POST['LinAcc']; $pressure =
$_POST['Pressure']; $proximity = $_POST['Proximity']; $humidity =
$_POST['Humidity'];
$rotVec = $_POST['RotVec']; $format = $_POST['Format']; $start =
$_POST['Start']; $finish = $_POST['Finish']; $first =
$_POST['First'];
$last = $_POST['Last'];
$sql2 = "INSERT into mobile_metadata(ID, Acc, Mag, Gyr,
Temperature, Grav, LinAcc, Pressure, Proximity, Humidity, RotVec,
Format, Start, Finish,
First, Last) VALUES ($id, $acc, $mag, $gyr, $temperature, $grav,
$light, $linAcc, $pressure, $proximity, $humidity, $rotVec,
$format, $start,
$finish, $first, $last);";
$result2 = mysql_query($sql2);
//Data uploaded
if($result2){
$response['Success'] = 1;
$response['Message'] = "Data uploaded succesfuly";
echo json_encode($response);
}
//Couldnt upload data
else{
$response["phpError"] = mysql_error();
$response['Success'] = 0;
$response['Message'] = "Oops! Couldnt upload data";
$response['Start'] = $_POST['Start'];
echo json_encode($response);
}
}
//Couldnt create the table
else{
$response["phpError"] = mysql_error();
$response["Success"] = 0;
$response["Message"] = "Oops! Couldnt create the table";
echo json_encode($response);
}
?>
Thanks
No comments:
Post a Comment