Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I need help to fix this problem.. i already sending data with curl, but it doesnt appears in database
here is my code ...

curl.php
PHP
  1  <?php
  2  error_reporting(0);
  3  session_start();
  4  $url    = "http://localhost/db_eis/izin_full_insert.php";
  5  
  6  $post = [
  7  	$no_pengajuan_full_day = $_POST['no_pengajuan_full_day'];
  8  	$nik_full_day = $_POST['nik_full_day'];
  9  	$jabatan_full_day  = $_POST['jabatan_full_day'];
 10  	$jenis_full_day  = $_POST['jenis_full_day'];
 11  
 12  	$start_full_day = $_POST['start_full_day'];
 13  	$karyawan_pengganti = $_POST['karyawan_pengganti'];
 14  	$ket_tambahan = $_POST['ket_tambahan'];
 15  	$status_full_day = $_POST['status_full_day'];
 16  	$status_full_day_2 = $_POST['status_full_day_2']; 
 17  
 18  		$image = base64_decode($_POST['upload_full_day']);
 19   
 20      	$nama = $no_pengajuan_full_day.".jpeg";
 21   
 22      	$targer_dir = "C:/xampp/htdocs/eis/uploads/izin/full_day/".$nama;
 23      	if (file_put_contents($targer_dir, $image)) {
 24          echo json_encode(array('response'=>'Success'));
 25      	}else{
 26          echo json_encode(array("response" => "Image not uploaded"));
 27      	}
 28      $nama = $_POST['upload_full_day']; 
 29  ];
 30  
 31  $ch = curl_init();
 32  curl_setopt($ch, CURLOPT_URL, $url);
 33  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 34  curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
 35  
 36  $output = curl_exec($ch);
 37  curl_close($ch);
 38  
 39  $result = json_decode($output); 
 40  ?>

izin_full_insert.php
PHP
  1  <?php
  2  include 'connect2.php';
  3  $tanggal = date('Y-m-d');
  4  
  5  $sql = "INSERT INTO tbl_izin_full_day
  6  (no_pengajuan_full_day,
  7  	nik_full_day,
  8  	jabatan_full_day,
  9  	jenis_full_day,
 10  	start_full_day,
 11  	karyawan_pengganti,
 12  	ket_tambahan,
 13  	status_full_day,
 14  	status_full_day_2,
 15  	upload_full_day) 
 16  
 17  	VALUES (
 18  	'$no_pengajuan_full_day',
 19  	'$nik_full_day',
 20  	'$jabatan_full_day',
 21  	'$jenis_full_day',
 22  	'$start_full_day',
 23  	'$karyawan_pengganti',
 24  	'$ket_tambahan',
 25  	'$status_full_day',
 26  	'$status_full_day_2',
 27  	'$nama'
 28  	)";
 29  $result = mysqli_query($conn, $sql);
 30  ?>


What I have tried:

it keeps error..
the error message says

Parse error: syntax error, unexpected ';', expecting ']' in C:\xampp\htdocs\eis_api\curl.php on line 7
Posted
Updated 2-Nov-20 3:29am
v2
Comments
Richard Deeming 2-Nov-20 9:14am    
You have a much bigger problem. Your code is vulnerable to SQL Injection[^]. NEVER use string concatenation / interpolation to build a SQL query. ALWAYS use a parameterized query.

PHP: SQL Injection - Manual[^]

Your array creation syntax looks nothing like the documentation:
PHP: Arrays - Manual[^]

The closest seems to be the new syntax from 5.4.0:
PHP: New features - Manual[^]

That would still need to be:
PHP
$post = [
    "no_pengajuan_full_day" => $_POST['no_pengajuan_full_day'],
    "nik_full_day" => $_POST['nik_full_day'],
    ...
];

NB: Don't ignore the SQL Injection[^] vulnerability in your izin_full_insert.php code. This is a critical vulnerability which is trivial to exploit, and could result in the complete destruction of your site.

PHP: SQL Injection - Manual[^]
PHP: Prepared statements and stored procedures - Manual[^]
 
Share this answer
 
Your syntax is incorrect for the declaration of $post. The correct way to specify arrays is detailed at PHP: Arrays - Manual[^].

Also take careful note of Richard Deeming's comment.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900