Monday, January 17, 2011

Php and Simple XML with namespace

<?php
$xmlString=<<<XML
<?xml version="1.0" encoding="ISO-8859-1"?>
     <Processrere>
    <ProcessDispositionDocumentResponses>
        <ProcessDispositionDocumentResponse>
            <ns0:Rsere> SCANNER.TIF302.42.236</ns0:Rsere>
        <ns0:Doser>1545421</ns0:Doser>
         <ns0:Caseser>130803</ns0:Caseser>
       </ns0:ProcessDispositionDocumentResponse>
  </ns0:ProcessDispositionDocumentResponses></ns0:Processrere>
XML;

$modifiedData = str_replace("ns0:", "", $xmlString);
$xml = simplexml_load_string($xmlString1);
$xml = simplexml_load_string($modifiedData);

//echo $xml->getName() . "<br />";

foreach($xml->children()->children()->children() as $child)
  {
 if ($child->getName() ==="CaseNumber"){
     $caseNumber=$child;
 }
  }
  echo $caseNumber;

Sunday, January 16, 2011

Ajax MySql Php

<html>
<head>
  
<script src=
"http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"
type="text/javascript">
</script>
    <script type="text/javascript">
      function register(){
    //    window.open("/welcome.html",'
welcome','width=300,height=200,menubar=yes,status=yes,location=yes,toolbar=yes,scrollbars=yes');
        $.ajax({
            type: "POST",
            url: "/ReturnData.php",
            data:     "username=" + document.getElementById("
username").value +
                    "&email=" + document.getElementById("
email").value,
            success: function(html){
                $("#response").html(html);
            }
        });
        }
    </script>
  </head>



<body>

    <form action="" method="post">
            <p>
                <label for="name">Name:</label><br />
                <input type="text" name="username" id="username" size="25" />
            </p>
            <p>
                <label for="email">Email:</label><br />
                <input type="text" name="email" id="email" size="25" />
            </p>
            <p>
                <input type="button" name="submit" id="submit" value="Subscribe" onclick="register()"/>
            </p>
            <ul id="mylist">
                <li><a rel="3" href="/#dave">Dave's email address</a></li>
                <li><a rel="4" href="/#erik">Erik's email address</a></li>
            </ul>

<p id="info">&nbsp;</p>

    <div id="response">
    </div>
</form>
</body>
</html>


<?php

                $db_host = 'localhost';
                $db_user = 'root';
                $db_pass = 'root';
                $db_name = 'db';
        $Username = $_POST['username'];
        $Email    = $_POST['email'];
     
        $connect = mysql_connect( $db_host, $db_user, $db_pass ) or die( mysql_error());
        $connection = $connect;
        mysql_select_db( $db_name, $connect ) or die( mysql_error() );
         echo $Username;
        $qInsertUser = mysql_query(" INSERT INTO test
                              
       VALUES ('$Username','$Email')
                              
    ");
        $qGetDetails = mysql_query("SELECT * FROM test");
   
   
         $num=mysql_numrows($
qGetDetails);
         echo $num;
         echo "hi";
        $i=0;
        while ($row=mysql_fetch_array($
qGetDetails)) {
        echo "<br>".$row['name'];
        }
    ?>
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
<script type="text/javascript">
$('document').ready(function()
{
    $('#mylist a').click(function ()
    {
        var id = $(this).attr('rel');

        $.getJSON('/return.php', {'id' : id}, parseInfo);
    });
});

function parseInfo(data)
{
    $('#info').html(data.name +', '+ data.email);
}
</script>
</head>
<body>
<ul id="mylist">
<li><a rel="3" href="#">Dave's email address</a></li>
<li><a rel="4" href="#">Erik's email address</a></li>
</ul>

<p id="info">
&nbsp;</p>
</body>
</html>

<?php

// see if we have a GET variable 'id' set
$id = (isset($_GET['id']) && !empty($_GET['id'])) ? $_GET['id'] : 0;

// pretend this is a query to a database to fetch the wanted users.
$users[3] = array('name' => 'Dave', 'email' => 'dave@adeepersilence.be');
$users[4] = array('name' => 'Erik', 'email' => 'erik@bauffman.be');

// only if an ID was given and the key exists in the array, we continue
if(!empty($id) && key_exists($id, $users))
{
// echo (not return) the wanted record from the users array
echo json_encode($users[$id]);
}

?>