Hii i want to save data to the database when user register. I dont know whats wrong.

Am having this error:
Warning: DOMDocument::loadXML() [domdocument.loadxml]: Empty string supplied as input in C:\Program Files (x86)\EasyPHP-5.3.6.0\www\TestingAjaxRegistration\register_pro.php on line 13

Warning: DOMDocument::schemaValidate() [domdocument.schemavalidate]: The document has no document element. in C:\Program Files (x86)\EasyPHP-5.3.6.0\www\TestingAjaxRegistration\register_pro.php on line 15
Your xml is not valid


home.html

<html>
<body>
<script type="text/javascript">

	var xml_members="";
	xml_members="<members></members>";

	function loadXMLString(txt)
	  {
		var xmlDoc;

		try //Internet Explorer
		{
		  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		  xmlDoc.async="false";
		  xmlDoc.loadXML(txt);
		  //xmlDoc.encoding="UTF-8";
		  return xmlDoc;
		}
		catch(e)
		{
		  try //Firefox, Mozilla, Opera, etc.
		  {
			parser=new DOMParser();
			xmlDoc=parser.parseFromString(txt,"text/xml");
			xmlDoc.encoding="UTF-8";
			return xmlDoc;
		  }
		  catch(e) {alert(e.message)}
		}
		return(null);
	  }//end function loadXMLString;

	 var txt_XML = document.getElementById("txt_xml_registration");
	 txt_XML.value="<members><member><firstname>"+document.getElementById("fname").value+"</firstname><lastname>"+document.getElementById("lname").value+"</lastname><emailaddress>"+document.getElementById("email").value+"</emailaddress><password>"+document.getElementById("password").value+"</password><gender>"+document.getElementById("gender").value+"</gender><birthday>"+document.getElemenetById("birthday").value+"</birthday></member></members>"

	 


</script>

<form method="post" action="register.php">
	<label>First name</label>
	<input type="text" name="fname"/>
				
	<label>Last name</label>
	<input type="text" name="lname"/>
				
	<label>Email Address</label>
	<input type="text" name="email" />
				   
	<label>Password</label>
	<input type="password" name="password"/>
				
	<label>Gender</label>
	<select name="gender">
		<option>Please select your gender.</option>
		<option>Female</option>	    
		<option>Male</option>
		</select>
				
	<label>Birthday</label>
	<input type="date" name="birthday"/>

	<input type="submit" name="submit" value="Submit" />
	<input type ="hidden" name="txt_xml_registration" id="txt_xml_registration"/>
</form>
			

</body>
</html>

register.php:

<?php

	$firstname="";
	$lastname="";
	$email="";
	$password="";
	$gender="";
	$birthday="";
	
	$members=$_POST['txt_xml_registration'];
	
	$xml_Doc = new DOMDocument();
	$xml_Doc->loadXML($members);
	
	if(!$xml_Doc->schemaValidate('member.xsd'))
		echo "Your xml is not valid";
	else
	{	
		include ("db_connect.php");
		header ('Content-Type: text/xml');
		$xml_members=simplexml_import_dom($xml_Doc);
		
		foreach ($xml_members->member as $member)
		{
			$firstname=$member->firstname;
			$lastname=$member->lastname;
			$email=$member->email;
			$password=$member->password;
			$gender=$member->gender;
			$birthday=$member->birthday;
			
			if ($firstname!="" && $firstname!=null)
			{
				$sql_query="INSERT INTO user (firstname,lastname,emailaddress,password,gender,birthday) VALUES ('$firstname','$lastname','$emailaddress','$password','$gender','$birthday')";
				if (!mysql_query($sql_query,$con))
				{
					die('Error: '.mysql_error());
				}
			}
		}
	}
$xml_output = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>";
$xml_output=$xml_output."<?xml-stylesheet type=\"text/xsl\" href=\"member.xsl\"?>";
$xml_output = $xml_output.$members;
echo $xml_output;
?>

It says $members is an empty string. Check with debug tools whether your hidden input has a value set, before submitting the form. If it is empty, then there is something wrong with your javascript.

This article has been dead for over six months. Start a new discussion instead.