2 Replies - 421 Views - Last Post: 15 September 2012 - 12:35 PM Rate Topic: ***** 1 Votes

#1 Taero  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 03-May 12

PDO Web Service & Silverlight & MySQL

Posted 14 September 2012 - 06:57 PM

Hi,

I have created a web service using PDO's in PHP, as seen here.:
<?php
session_start();
try {
	$dbh = new PDO("serverhere;dbname=DBhere",'userhere', 'passwordhere');
} catch (PDOException $e)
{
	echo $e->getMessage();
}
if ($_POST['user'] != null and $_POST['user'] != "" && $_POST['password'] != null and $_POST['password'] != "")
{
	
	$username = $_POST['user'];
	$password = $_POST['password'];
	
	
	echo '$_POST[user] = '. $_POST['user']."<br/>";
	echo '$_POST[password] = '.$_POST['password']."<br/>";
	
	echo 'username = '.$username."<br/>";
	echo 'password = '.$password."<br/>";
	
	//$sth = $dbh->prepare("SELECT * FROM users");
	$sth = $dbh->prepare("SELECT * FROM users WHERE email=:username and password= :password");
	$sth->bindParam(":username", $username);
	$sth->bindParam(":password", $password);
	
	echo "<br/>";
	print_r($sth);
	echo "<br/>";
	$sth->execute();
	//print_r($sth);
	$result = $sth->fetchAll();
	print_r($result);
	//$sth1 = $dbh->query("SELECT * FROM users");
	
	/*echo "<br/>";
	echo $result[0];
	echo $result[0]->{'COUNT(*)'};*/
	
} else
{
	echo "I went to the else";
	echo "-". $_POST['user'];
	echo "-".$_POST['password'];
}

?>



To consume the web service in php I have this HTML form:

<html>
<body>
<form method="POST" action="http://someservice.php">
  Username: <input type="text" name="user" size="15" /><br />
  Password: <input type="password" name="password" size="15" /><br />
  <div align="center">
    <p><input type="submit" value="Login" /></p>
  </div>
</form>
</body>
</html>



When using this HTML form I get the following results for user=hey, and password=guy (a test account I have in MySQL)

heyguyheyguyjustb4query
PDOStatement Object ( [queryString] => SELECT * FROM users WHERE email=:username and password= :password ) 
Array ( [0] => Array ( [UserID] => 2 [0] => 2 [email] => hey [1] => hey [password] => guy ) ) 



Now in Silverlight I get this response to the same values:
heyguy
heyguy
justb4query<br/>PDOStatement Object
(
    [queryString] => SELECT * FROM users WHERE email=:username and password= :password
)
<br/>Array
(
)



Now I originally assumed that something in the .net framework was not getting the response back properly, but I decided to test this first:
So I rewrite the SQL and remove the variables changing:

This:
SELECT * FROM users WHERE email=:username and password= :password

To this:
SELECT * FROM users

Now my results in the HTML form are this:
$_POST[user] = hey
$_POST[password] = guy
username = hey
password = guy

PDOStatement Object ( [queryString] => SELECT * FROM users )
Array ( [0] => Array ( [UserID] => 2 [0] => 2 [email] => hey [1] => hey [password] => guy [2] => guy)



Targeting that same web service in Silverlight I get this:
$_POST[user] = hey<br/>$_POST[password] = guy
<br/>username = hey<br/>password = guy
<br/><br/>PDOStatement Object
(
    [queryString] => SELECT * FROM users
)
<br/>Array
(
    [0] => Array
        (
            [UserID] => 2
            [0] => 2
            [email] => hey
            [1] => hey
            [password] => guy
            [2] => guy
         )



So now I am not sure what is hindering my SQL statement that has a WHERE clause, if you have any idea PLEASE let me know, I really appreciate it!

Is This A Good Question/Topic? 0
  • +

Replies To: PDO Web Service & Silverlight & MySQL

#2 Taero  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 03-May 12

Re: PDO Web Service & Silverlight & MySQL

Posted 14 September 2012 - 07:05 PM

I wish there was some way to edit my original post...
I added "$_POST[variable] = " to the echos of my web service for this forum posts readability...But forgot to update before posting. Sorry.
Was This Post Helpful? 0
  • +
  • -

#3 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10771
  • View blog
  • Posts: 40,110
  • Joined: 27-December 08

Re: PDO Web Service & Silverlight & MySQL

Posted 15 September 2012 - 12:35 PM

Please avoid duplicate posting.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1