-1

Hi..I need help...I am using the following

<?php
$username="";
$password="";
$firstname="";
$lastname="";
$ydob="";
$mdob="";
$bdob="";
$email="";
$gender="";
$priority="";
$usid="";

$users= $_POST['txt_xml_users'];


 $xml_Doc = new DOMDocument();
 $xml_Doc->loadXML($users);
 
 
 if(!$xml_Doc->schemaValidate('users.xsd'))
   echo "Your xml is NOT valid";

 else
 {
    include("dbconnect.php");
   header('Content-Type: text/xml');
  //$xml_users=simplexml_load_string($users );
    $xml_users=simplexml_import_dom($xml_Doc);

    foreach ($xml_users->user as $user)
    {
      $username=$user->username;
      $password=$user->password;
      $firstname=$user->firstname;
      $lastname=$user->lastname;
      $ydob=$user->ydob;
      $mdob=$user->mdob;
      $bdob=$user->bdob;
      $email=$user->email;
      $gender=$user->gender;
      $priority=$user->priority;
      $usid=$user->usid;

      if($username!="" && $username!=null)
      {
       $sql_select="SELECT * FROM users WHERE 

username='$username'";
	       
       $Rs = mysql_query($sql_select);

       if (mysql_num_rows($Rs)<1)

	if($password!="" && $password!=null)
      {
       $sql_select="SELECT * FROM users WHERE 

password='$password'";
	       
       $Rs = mysql_query($sql_select);

       if (mysql_num_rows($Rs)<1)

	if($firstname!="" && $firstname!=null)
      {
       $sql_select="SELECT * FROM users WHERE 

firstname='$firstname'";
	       
       $Rs = mysql_query($sql_select);

       if (mysql_num_rows($Rs)<1)

	if($lastname!="" && $lastname!=null)
      {
       $sql_select="SELECT * FROM users WHERE 

lastname='$lastname'";
	       
       $Rs = mysql_query($sql_select);

       if (mysql_num_rows($Rs)<1)


	if($ydob!="" && $ydob!=null)
      {
       $sql_select="SELECT * FROM users WHERE ydob='$ydob'";
	       
       $Rs = mysql_query($sql_select);

       if (mysql_num_rows($Rs)<1)


	if($mdob!="" && $mdob!=null)
      {
       $sql_select="SELECT * FROM users WHERE mdob='$mdob'";
	       
       $Rs = mysql_query($sql_select);

       if (mysql_num_rows($Rs)<1)


	if($bdob!="" && $bdob!=null)
      {
       $sql_select="SELECT * FROM users WHERE bdob='$bdob'";
	       
       $Rs = mysql_query($sql_select);

       if (mysql_num_rows($Rs)<1)


	if($email!="" && $email!=null)
      {
       $sql_select="SELECT * FROM users WHERE email='$email'";
	       
       $Rs = mysql_query($sql_select);

       if (mysql_num_rows($Rs)<1)


	if($gender!="" && $gender!=null)
      {
       $sql_select="SELECT * FROM users WHERE gender='$gender'";
	       
       $Rs = mysql_query($sql_select);

       if (mysql_num_rows($Rs)<1)


	if($priority!="" && $priority!=null)
      {
       $sql_select="SELECT * FROM users WHERE 

priority='$priority'";
	       
       $Rs = mysql_query($sql_select);

       if (mysql_num_rows($Rs)<1)


	if($usid!="" && $usid!=null)
      {
       $sql_select="SELECT * FROM users WHERE usid='$usid'";
	       
       $Rs = mysql_query($sql_select);

       if (mysql_num_rows($Rs)<1)//insert only if the data has not 

been inserted before
       {
       //we want to insert data

         $sql_insert="INSERT INTO 

modules(username,password,firstname,lastname,ydob,mdob,bdob,email,

gender,priority,usid)VALUES('$username','$password','$firstname','

$lastname','$ydob','$mdob','$bdob','$email','$gender','$priority',

'$usid')";

         if (!mysql_query($sql_insert,$con))
         {
           die('Error: ' . mysql_error());
         }
               }//end if
              }//end if
             }//end if
            }//end if
           }//end if
          }//end if
         }//end if
        }//end if
       }//end if
      }//end if
     }//end if
    }//end foreach
?>
<?
  mysql_close($con);
    }//end else


?>

Am getting error

Parse error: syntax error, unexpected $end in D:\xampp\htdocs\xampp\csite\process_reg.php on line 157

3
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by broj1
2

Man, you must be in love with the if clause. It seems that you have one curly bracket missing at the end between lines 168 and 179. Your code is very complex and hard to follow but my IDE shows that what is marked as:

}//end foreach

is really end of if block starting on line 45. If I insert a curly bracket at the end, all the brackets are in pairs but I do not know whether the code is what you intended.

0

Yes yes... But now am getting this :

Notice: Undefined index: txt_xml_users in D:\xampp\htdocs\xampp\csite\process_reg.php on line 15

Warning: DOMDocument::loadXML() [domdocument.loadxml]: Empty string supplied as input in D:\xampp\htdocs\xampp\csite\process_reg.php on line 18

Warning: DOMDocument::schemaValidate() [domdocument.schemavalidate]: The document has no document element. in D:\xampp\htdocs\xampp\csite\process_reg.php on line 21
Your xml is NOT valid ?>

:s

0

Actually you only have one error which is the line #15. If you can correct it, the error in the line 18 and 21 will be corrected too. I think the previous declarations of your variable will be the cause of that error.

broj1 actually solved your previous problem, and it is time for you to use your logical ability as a future programmer to solve this kind of error code..

Enjoy!

0
<?php

$username="";
$password="";
$firstname="";
$lastname="";
$ydob="";
$mdob="";
$bdob="";
$email="";
$gender="";
$priority="";
$usid="";

$users= $_POST['txt_xml_users'];

  $xml_Doc= new DomDocument();
  $xml_Doc->formatOutput = true;  
  $test1 = $xml_Doc->saveXML(); 
  $xml_Doc->save('users.xml');

 
 if(!$xml_Doc->schemaValidate('users.xsd'))
   echo "Your xml is NOT valid";

 else
 {
    include("dbconnect.php");
   header('Content-Type: text/xml');
  //$xml_users=simplexml_load_string($users);
    $xml_users=simplexml_import_dom($xml_Doc);
    foreach ($xml_users->user as $user)
    {
      $username=$user->username;
      $password=$user->password;
      $firstname=$user->firstname;
      $lastname=$user->lastname;
      $ydob=$user->ydob;
      $mdob=$user->mdob;
      $bdob=$user->bdob;
      $email=$user->email;
      $gender=$user->gender;
      $priority=$user->priority;
      $usid=$user->usid;

      if($username!="" && $username!=null)
      {
       $sql_select="SELECT * FROM users WHERE 

username='$username'";
	      
         $Rs = mysql_query($sql_select);

       if (mysql_num_rows($Rs)<1)

	if($password!="" && $password!=null)
      {
       $sql_select="SELECT * FROM users WHERE 

password='$password'";
	        
       $Rs = mysql_query($sql_select);

       if (mysql_num_rows($Rs)<1)

	if($firstname!="" && $firstname!=null)
      {
       $sql_select="SELECT * FROM users WHERE 

firstname='$firstname'";
	         
     $Rs = mysql_query($sql_select);

       if (mysql_num_rows($Rs)<1)

	if($lastname!="" && $lastname!=null)
      {
       $sql_select="SELECT * FROM users WHERE 

lastname='$lastname'";
	           
    $Rs = mysql_query($sql_select);

       if (mysql_num_rows($Rs)<1)


	if($ydob!="" && $ydob!=null)
      {
       $sql_select="SELECT * FROM users WHERE ydob='$ydob'";
	        
       $Rs = mysql_query($sql_select);

       if (mysql_num_rows($Rs)<1)


	if($mdob!="" && $mdob!=null)
      {
       $sql_select="SELECT * FROM users WHERE mdob='$mdob'";
	         
      $Rs = mysql_query($sql_select);

       if (mysql_num_rows($Rs)<1)


	if($bdob!="" && $bdob!=null)
      {
       $sql_select="SELECT * FROM users WHERE bdob='$bdob'";
	          
     $Rs = mysql_query($sql_select);

       if (mysql_num_rows($Rs)<1)


	if($email!="" && $email!=null)
      {
       $sql_select="SELECT * FROM users WHERE email='$email'";
	          
     $Rs = mysql_query($sql_select);

       if (mysql_num_rows($Rs)<1)


	if($gender!="" && $gender!=null)
      {
       $sql_select="SELECT * FROM users WHERE gender='$gender'";
	          
     $Rs = mysql_query($sql_select);

       if (mysql_num_rows($Rs)<1)


	if($priority!="" && $priority!=null)
      {
       $sql_select="SELECT * FROM users WHERE 

priority='$priority'";
	         
      $Rs = mysql_query($sql_select);

       if (mysql_num_rows($Rs)<1)


	if($usid!="" && $usid!=null)
      {
       $sql_select="SELECT * FROM users WHERE usid='$usid'";
	          
     $Rs = mysql_query($sql_select);

       if (mysql_num_rows($Rs)<1)//insert only if the data has not 

been inserted before
       {
       //we want to insert data

         $sql_insert="INSERT INTO 

users(username,password,firstname,lastname,ydob,mdob,bdob,email,ge

nder,priority,usid)values('$username','$password','$firstname','$l

astname','$ydob','$mdob','$bdob','$email','$gender','$priority','$

usid')";

         if (!mysql_query($sql_insert,$con))
         {
           die('Error: ' . mysql_error());
         }
                }//end if
               }//end if
              }//end if
             }//end if
            }//end if
           }//end if
          }//end if
         }//end if
        }//end if
       }//end if
      }//end if
     }//end if
    }//end foreach

?>

<?php
  mysql_close($con);
    }//end else

?>

 ?>

I am getting error...I have to submit this in 1hour...

Notice: Undefined index: txt_xml_users in D:\xampp\htdocs\xampp\csite\process_reg.php on line 15

Warning: DOMDocument::schemaValidate() [domdocument.schemavalidate]: The document has no document element. in D:\xampp\htdocs\xampp\csite\process_reg.php on line 23
Your xml is NOT valid ?>

0

Obviously $_POST array does not contain a 'txt_xml_users' key which suggests that this data has not been supplied by the form. You have to implement some means of checking for valid input such as:

if(!isset($_POST['txt_xml_users'] or empty($_POST['txt_xml_users'])) {

   // warn the user to enter valid data
} else {

   // do all your normal processing here
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.