views:

158

answers:

4

Here is my code

    <form method="post">
  <input name="hash" type="text" id="hash" style='width: 30%;'/>
    <input name="Crack!" type="submit" value="Crack!" onfocus="if(this.blur)this.blur()"/>
</form>

    <?php
 if(isset($_POST['Crack!'])){
  $hash = $_POST['hash'];        

     $xml = simplexml_load_file("http://gdataonline.com/qkhash.php?mode=xml&amp;hash=$hash");

  $status = $xml->data->status; 
    if ($status = "Success"){
     $plain = $xml->data->result;
      }elseif ($status = "Hash not found"){
      $plain = "Not Found"; }     

?>
 <table>
 <tr>  
 <td><?php echo "gdataonline.com: "; ?></td>
 <td><?php echo "$plain"; ?></td>
 </tr>
 </table>

<?php
echo "<pre>";
var_dump($xml);
echo "</pre>"; 

 } //if submit

 ?>

For some reason I can't get it to echo $plain, at all. Its as if it can't even read it. Anyone know why?

+1  A: 

Where are you getting "$xml->data"? According to php.net there is no member of the SimpleXMLElement object called "data". See that link or the documentation for simplexml_load_file for numerous examples on using this properly.

Brian Lacy
Rob
+1  A: 

It may not be your entire problem, but one definite problem is that you've got two assignments instead of tests:

if ($status = "Success")

and

}elseif ($status = "Hash not found"){

are both assigning those values to $status instead of testing equality. You want $status == "Success" and $status == "Hash not found"

In this case your first test will always succeed (because the return value of assignment is the value assigned, so $status = "Success" will return "Success" which will evaluate to true in an 'if' test, so $plain will always be $xml->data->result, even if the status wasn't really success.

sidereal
You're right, I don't know how I missed that. Thanks! But again I still have the same problem, but it was still necessary, thank you.
Rob
+3  A: 

Rob, if you want people to even understand your question you have to make an effort instead of just posting a huge chunk of irrelevant code and ask "why does this not work?"

So I did your homework, I figured out what the script was doing and fetched an example XML document. As it turns out, you got the hierarchy wrong. Also, this is unrelated but you are using assignment operators instead of comparison operators. In other words, your ifs don't test anything, the first one just sets $status to "Success".

The relevant portion should be something like this:

$data = simplexml_load_file("http://gdataonline.com/qkhash.php?mode=xml&amp;hash=$hash");

switch ($data->status)
{
    case 'Success':
        $plain = $data->result;
        break;

    case 'Hash not found':
        $plain = "Not Found";
        break;
}
Josh Davis
Yeah your code rooks :-)
streetparade
Thanks a lot! Worked like a charm!
Rob
A: 

This worked for me :

<form method="post">
  <input name="hash" type="text" id="hash" style='width: 30%;'/>
    <input name="Crack!" type="submit" value="Crack!" onfocus="if(this.blur)this.blur()"/>
</form>

    <?php
 if(isset($_POST['Crack!'])){
  $hash = $_POST['hash'];        

<?php

$xml = simplexml_load_file("http://gdataonline.com/qkhash.php?mode=xml&amp;hash=$hash")

if(!xml)
{
 echo "hash not found";
 // return false; // not function so cant return false ignore it
}

$plain = $xml->result;

?>


<table>
 <tr>
 <td><?php echo "gdataonline.com: "; ?></td>
 <td><?php echo "$plain"; ?></td>
 </tr>
 </table>
streetparade