odk with php mysql

<?php
//With default Collect Submission path setting, this script would be located at https://your.server/submission/index.php
//this is where all the uploaded files will eventually be stored.
$datapath='/path/to/your/datafiles/';
//Set a variable to tell us whether an XML file has successfully been uploaded later:
$xmlfile=false;
//we need to process POST and HEAD requests separately, and cater for GET just in case
$method=strtolower($_SERVER['REQUEST_METHOD']);
//Issue these response headers to both HEAD and POST requests:
header("Content-Type: text/xml; charset=utf-8");
header("Content-Language: en");
header("X-OpenRosa-Version: 1.0");
header("X-OpenRosa-Accept-Content-Length: 10000000");//limit upload to 10Mb - probably too high for most realistic scenarios!
//Now process POST and HEAD requests differently
if ($method=='post') {
	//we should have at least one POSTED file
	if (isset($_FILES)) {
		//we need to move all the POSTed files from the tmp upload folder, as with any file POST, then respond with a Success code and message.
		foreach($_FILES as $file) {
			$filename=$file['name'];
			$ok=move_uploaded_file($file['tmp_name'],$datapath.$filename);
			//There should only be one XML file, which is the completed form.  Any other files are assets, whose file names will be included in the form data.
			if ($file['type']=="text/xml") $xmlfile=$file['name'];
		}
		header("HTTP/1.1 202 Accepted");
		echo '<?xml version="1.0" encoding="UTF-8" ?>';
		echo '<OpenRosaResponse xmlns="http://openrosa.org/http/response" items="1">';
		echo '<message nature="submit_success">Form submitted successfully</message>';
		echo '</OpenRosaResponse>';	
	}
	else {
		/* If $_FILES is not set in the POST, that means we have no XML file of the completed form, so we need to return an error.  This should really be a 400, but 
		in my original implementation circa 2012, Collect didn't interpret a 400 response correctly, and only a 403 response would produce a human-readable 
		error message in Collect. */
		header("HTTP/1.1 403 Forbidden");
		echo '<?xml version="1.0" encoding="UTF-8" ?>';
		echo '<OpenRosaResponse xmlns="http://openrosa.org/http/response" items="1">';
		echo  '<message nature="submit_success">Submission unsuccessful - no data files were received.</message>';
		echo '</OpenRosaResponse>';	
	}
}
if ($method=='head' || $method=='get') { 
	//This is the initial HEAD request from Collect, so we need to return a Location header telling Collect where to POST the completed form.  
	//We also provide this response to GET requests to give us browser testing options.
	header("Location: $_SERVER[SCRIPT_URI]");//this script - 
	header("HTTP/1.1 204 No Content");//that's all, no actual content in the response.
}
if ($xmlfile!==false){
  //now process the contents of $path.$xmlfile however you want to!
  require 'my_form_processor_script.php';	
}
?>

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source