Jump to content


Photo

my problem with jquery and oop php ? is there anyone ?


  • Please log in to reply
5 replies to this topic

#1 redhat2

redhat2

    Newbie

  • New Members
  • Pip
  • 6 posts

Posted 19 January 2013 - 03:08 AM

i have three page code in the following :

[/size][/font][/color]
<?php 
require_once('includes/funcs.class.php');
$objectUser = new func("localhost","root","","mesaeed");
if(isset($_POST['username']))
{
$objectUser->existUsername($_POST['username']); 
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
&lt;script src="js/jquery-1.9.0.min.js" type="text/j&#097;v&#097;script"></script>
&lt;script src="js/juser.js" type="text/j&#097;v&#097;script"></script>
<link rel="stylesheet" href="style.css" />
</head>

<body>
<div class="divclass">
<form action="index.php" method="post" id="login">
Username : <input type="text" name="username" id="username" /><br /><br />
Password : <input type="text" name="password" id="password" /><br /><br />
<input type="submit" value="login" id="submitlogin" /><br /><br />
</form>
</div>
</body>
</html>
[color=#000000][font=Tahoma, Verdana, Arial][size=3]


funcs.class.php :

[/size][/font][/color]
<?php
require_once('connect.class.php');
class func extends connect
{
protected $_dbusername;
protected $_dbemail;
protected $_dbpassword;
//User ..... Functions .....
function existUsername($dbusername)
{
$this->_dbusername = $dbusername;
global $dbtable,$dbsql,$dbquery;
$dbtable = "users";
$dbsql = "SELECT * FROM ".$dbtable." WHERE username = ?";
$dbquery = $this->_connect->prepare($dbsql);
$dbquery->bind_param("s", $this->_dbusername);
$dbquery->execute();
$dbquery->store_result();
if($dbquery->num_rows == 1)
{
echo "1";
}
else
{
echo "0";
}
$dbquery->close();
}
?>
[color=#000000][font=Tahoma, Verdana, Arial][size=3]


jquery.js :


// J&#097;v&#097;script Document
$(document).ready(function(e) {
$("input#username").change(function(e) {
  var username = $("input#username").val()
  $.ajax({
   type: "POST",
   url: "index.php",
   data: {username: username},
   success: function(msg){
    if(msg == "1")
    {
     alert("Ok . ");
    }
    else
    {
     alert("No . ");
    }
    }
   });
    });
});[/size][/font][/color]
[color=#000000][font=Tahoma, Verdana, Arial][size=3]


but it doesnt work !!!!!
the orginal code enclosed .

Attached Files


Edited by redhat2, 19 January 2013 - 03:10 AM.


#2 requinix

requinix

    Hopeless Member

  • Moderators
  • 5,914 posts
  • LocationWA

Posted 19 January 2013 - 03:20 AM

You should probably fix it then.

If you need more specific advice than that, give us more to go on than "it doesn't work".

#3 redhat2

redhat2

    Newbie

  • New Members
  • Pip
  • 6 posts

Posted 19 January 2013 - 03:33 AM

when i enter the username : saeed ، (username is not in the database) -> alert no .
when i enter the username : admin (username in the datdabase) ->alert no .

#4 Christian F.

Christian F.

    Advanced Member

  • Staff Alumni
  • 3,106 posts
  • LocationNorway

Posted 19 January 2013 - 04:53 AM

Check the output from the PHP script, to ensure that it only sends what you expect. Any other content, even a whitespace, will make the check fail.
Keeping it simple.

#5 trq

trq

    Advanced Member

  • Administrators
  • 30,904 posts
  • LocationSydney, Australia.

Posted 19 January 2013 - 05:33 AM

And please, your code is NOT OOP.

http://thorpesystems.com | http://proemframework.org | http://github.com/trq

SmtpCatcher - A very simple mock sendmail useful for testing PHP mail scripts.
OPM - My Linux package manager.


#6 cpd

cpd

    ¬_¬

  • Members
  • PipPipPip
  • 881 posts
  • LocationLondon, UK

Posted 19 January 2013 - 08:03 AM

Not only is it not object oriented its illogical. It doesn't make sense: "class func extends connect"? What on earth is that meant to mean?

When creating inheritance hierarchies it should be logical and you should consider the question "Is class A a class B" E.g. Is a Car a Vehicle? "class Car extends Vehicle".

Edited by cpd, 19 January 2013 - 08:04 AM.

"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it."

"One of my most productive days was throwing away 1000 lines of code."




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com