i am having problem in uploading data to online mysql database. i am using scheduled tasks to run php script all the data is sent to the server through json_encode
and the data is received perfectly but when inserting into mysql database it only insert first alphabet of that data
this code gets the data
$da = $_GET['data'];
$d = json_decode($da, true);
by printing it shows complete data but only inserts the first alphabet of the data
$a = 0;
foreach($d as $data)
{
echo $v = "INSERT INTO clms_data(id,teacher_id,course_id,session,section,stDate,endDate,type,description,filename,allow) VALUES(".$data[$a][0].",'".$data[$a][1]."','".$data[$a][2]."','".$data[$a][3]."','".$data[$a][4]."','".$data[$a][5]."','".$data[$a][6]."','".$data[$a][7]."','".$data[$a][8]."','".$data[$a][9]."',".$data[$a]['allow'].")";
$qu = mysql_query($v) or die(mysql_error());
if($qu)
{
echo "Execute $a<br />";
}
else
{
echo "Error";
}
$a++;
}
Can't you do it by simple insert query with json
insert.php
<?php
include_once('connect.php');
error_reporting( error_reporting() & ~E_NOTICE );
$id= $_GET['id'];
$teacher_id= $_GET['teacher_id'];
$course_id= $_GET['course_id'];
$session= $_GET['session'];
{
$insert="INSERT INTO clms_data(id,teacher_id,course_id
,session)values
('$id','$teacher_id','$course_id',session)";
$result = mysqli_query($con, $insert);
if(!$result)
{
print("invalid query");
}
else
{
$output['success']=1;
$output['message']="Insert records successfully";
print(json_encode($output));
}
}
?>
Try this example with json Ask if there is any doubt
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.