ohad Posted May 29, 2020 Share Posted May 29, 2020 (edited) Hi I try to build a login form in which the user enter its userid, and the system check in the database for the user name and present it There are several other fiels that should act the same way. the problem is that the description field not get the user name. I be glad if someone show me where is the problem here is the code i use: The index.php page <!DOCTYPE html> <!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <?php require_once(".Includes/GlDbOra.php"); $logonSuccess = false; //get user details if (isset($_POST['userid_typed'])) { $row = (DBOracle::getInstance()->get_user_details1($_POST['userid'])); if(!$row) { echo "The user code entered in invalid"; } else { ?> <input type="text" name="userid_desc" id="user_desc" class="regular_textbox" value=<?php echo $row('username'); ?> readonly="readonly" disabled="disabled" /> <?php } } ?> <html> <head> <meta charset="UTF-8"> <title>Login</title> <script type="text/javascript" src="../../php-ajax/jquery-3.5.1.js"></script> <link href="index.css" type="text/css" rel="stylesheet" madia="all"/> </head> <body> <div class="logon"> <form name="logon" id="logon" action="index.php" method="POST" > <span style="clear: both; float: left; margin-top: 20px; "> <label for="userid">User Id</label> <input type="text" name="userid" id="userid" class="left_radius_textbox" placeholder="<?php echo userid;?>"/> <input type="text" name="userid_desc" id="user_desc" class="regular_textbox" value="" readonly="readonly" disabled="disabled" /> <label for="password">Password</label> <input type="password" name="password" id="password" class="regular_textbox" placeholder="<?php echo password;?>"/> </span> <span style="clear: both; float: left; margin-top: 20px"> <label for="compid">Company</label> <input type="text" name="compid" id="compid" class="left_radius_textbox" placeholder="<?php echo compid;?>"/> <input type="text" name="compid_desc" id="compid_desc" class="regular_textbox" value="" readonly="readonly" disabled="disabled" /> <label for="language">Language</label> <input type="text" name="language" id="language" class="left_radius_textbox" placeholder="<?php echo language;?>"/> <input type="text" name="language_desc" id="language_desc" class="regular_textbox" value="" readonly="readonly" disabled="disabled" /> </span> <span style="clear: both; float: right; margin-top: 20px"> <input type="submit" value="Login"style="margin-right: 500px; border-radius: 40px ; text-align:center;width: 220px; height: 30px;" class="" placeholder="<?php echo login;?>"/> </span> </form> </div> <script> $(document).ready() { $("#userid").focusout() { var userid=$('input[name=userid]').val(); $.ajax ({ type:"POST", url:"../AmiDorGL/Includes/GlDbOra.php", data: { "userid_typed":1, "userid":userid, }, datatype:"text", success:function(response) { $("#userid_desc").html(response); } }); }; }; </script> </body> </html> the GlDbOra.php code: <?php /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ class DBOracle { private static $instance = null; private $OracleUser="xxx"; private $OraclePwd="xxx"; private $OracleDB="xxx"; public static function getInstance() { if (!self::$instance instanceof self) { self::$instance = new self; } return self::$instance; } // The clone and wakeup methods prevents external instantiation of copies of the Singleton class, // thus eliminating the possibility of duplicate objects. public function __clone() { trigger_error('Clone is not allowed.', E_USER_ERROR); } public function __wakeup() { trigger_error('Deserializing is not allowed.', E_USER_ERROR); } public function __construct () { $this->con = oci_connect($this->OracleUser, $this->OraclePwd, $this->OracleDB); if (!$this->con) { $m = oci_error(); echo $m['message'], "\n"; exit; } } public function get_user_details1($userid) { $query = "select first_name||' '||last_name username, password from users where userid = :userid_bv"; $stid = oci_parse($this->con, $query); oci_bind_by_name($stid, ':userid_bv', $userid); oci_execute($stid); $row = oci_fetch_array($stid, OCI_ASSOC); return $row; } } Edited May 29, 2020 by requinix please use the Code <> button when posting code Quote Link to comment https://forums.phpfreaks.com/topic/310864-retreiving-data-from-database-upon-change-of-textbox/ Share on other sites More sharing options...
requinix Posted May 29, 2020 Share Posted May 29, 2020 Modify your AJAX so that it can handle an error response - perhaps by console.log-ing the response - then see if you get an error message from PHP showing where the problem is. (Spoiler: there is an error from PHP) Quote Link to comment https://forums.phpfreaks.com/topic/310864-retreiving-data-from-database-upon-change-of-textbox/#findComment-1578500 Share on other sites More sharing options...
ohad Posted May 29, 2020 Author Share Posted May 29, 2020 Thank for reply requinix, but the console.log doesnt show errors. only 1 suggestion to add autocomplete to the texbox.... this is the code i added: , error: function(response) { console.log(response.responseText); } im new to php and i might be doing something wrong Quote Link to comment https://forums.phpfreaks.com/topic/310864-retreiving-data-from-database-upon-change-of-textbox/#findComment-1578501 Share on other sites More sharing options...
requinix Posted May 29, 2020 Share Posted May 29, 2020 Try using your browser's developer console to watch the AJAX request itself. Pull it up, go to the network or whatever area, then type in the box and click away, and you should see the request go to the server and the response come back. Then take a look at it. Quote Link to comment https://forums.phpfreaks.com/topic/310864-retreiving-data-from-database-upon-change-of-textbox/#findComment-1578502 Share on other sites More sharing options...
ohad Posted May 30, 2020 Author Share Posted May 30, 2020 (edited) ok, i've found out that the code didnt send the userid to the function (and some few typos on the way too) but still after i enter userid code and press TAB the description is not filled. my idea is that the php function is not called at all. If I remove the if (isset($_POST['userid_typed'])) condition, when page is loaded the message The user code entered in invalid apears (and it understood cause no userid data enterd and the DB return no row). but after when i leave the userid textbox empty and press TAB it not show this message again. Maybe I miss something the way PHP work, and i might use the wrong event to catch TAB key pressed. Ill be happy for some advise here is my updated index.php code: <!DOCTYPE html> <!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <?php require_once("Includes/GlDbOra.php"); $logonSuccess = false; //get user details if (isset($_POST['userid_typed'])) { $userid=$_POST['userid']; $username = (DBOracle::getInstance()->get_user_details1($userid)); if(!$row) { echo "The user code entered in invalid"; } else { ?> <input type="text" name="userid_desc" id="userid_desc" class="regular_textbox" value="<?php echo $row['username']; ?>" disabled="disabled" /> <?php } } ?> <html> <head> <meta charset="UTF-8"> <title>Login</title> <script type="text/javascript" src="../../php-ajax/jquery-3.5.1.js"></script> <link href="index.css" type="text/css" rel="stylesheet" madia="all"/> </head> <body> <div class="logo_image"> <span style="clear: both; float: right; margin-top: 20px; margin-right: 840px;"> <img class="img" src="Images/back_white.jpg" alt="header" width="400" height="150"/> </span> </div> <div class="open_image"> <img class="img" src="Images/AmiDor_Open.png" alt="image" width="400" height="300"/> </div> <div class="logon"> <form name="logon" id="logon" action="index.php" method="POST" > <span style="clear: both; float: left; margin-top: 20px; "> <label for="userid">User Id</label> <input type="text" name="userid" id="userid" class="regular_textbox" placeholder="<?php echo userid;?>"/> <input type="text" name="userid_desc" id="userid_desc" class="regular_textbox" value="" disabled="disabled" /> <label for="password">Password</label> <input type="password" name="password" id="password" class="regular_textbox" placeholder="<?php echo password;?>"/> </span> <span style="clear: both; float: left; margin-top: 20px"> <label for="compid">Company</label> <input type="text" name="compid" id="compid" class="regular_textbox" placeholder="<?php echo compid;?>"/> <input type="text" name="compid_desc" id="compid_desc" class="regular_textbox" value="" readonly="readonly" disabled="disabled" /> <label for="language">Language</label> <input type="text" name="language" id="language" class="regular_textbox" placeholder="<?php echo language;?>"/> <input type="text" name="language_desc" id="language_desc" class="regular_textbox" value="" readonly="readonly" disabled="disabled" /> </span> <span style="clear: both; float: right; margin-top: 20px"> <input type="submit" value="Login" id="login" style="margin-right: 500px; border-radius: 40px ; text-align:center;width: 220px; height: 30px;" class="" placeholder="<?php echo login;?>"/> </span> </form> </div> <script> $(document).ready(function() { $('#userid').focusout(function() { //var userid=document.getElementById('#userid').value; var userid=$('input[name=userid]').val(); $.ajax ({ type:"POST", url:"GlDbOra.php", data: { "userid_typed": 1, "userid": userid, }, datatype:"text", success:function(response) { console.log(response); $("#userid_desc").html(response); }, error: function(response) { console.log(response.responseText+errortext); } }); }); }); </script> </body> </html> Edited May 30, 2020 by requinix Quote Link to comment https://forums.phpfreaks.com/topic/310864-retreiving-data-from-database-upon-change-of-textbox/#findComment-1578513 Share on other sites More sharing options...
requinix Posted May 30, 2020 Share Posted May 30, 2020 Please use the Code <> button when posting code. I fixed your first post earlier and your second post just now. And for the love of everything that's holy, if you're not using a license header then don't use a license header. $username = (DBOracle::getInstance()->get_user_details1($userid)); if(!$row) Look at those two lines. Read them to yourself out loud. If you can't see the issue, step away from the computer for a while, make a sandwich or play some games, then come back and check again. Quote Link to comment https://forums.phpfreaks.com/topic/310864-retreiving-data-from-database-upon-change-of-textbox/#findComment-1578524 Share on other sites More sharing options...
ohad Posted May 30, 2020 Author Share Posted May 30, 2020 Till you replied I already noticed that and fixed it. I couldnt find a way to delete a post here. Sorry for that Quote Link to comment https://forums.phpfreaks.com/topic/310864-retreiving-data-from-database-upon-change-of-textbox/#findComment-1578530 Share on other sites More sharing options...
requinix Posted May 30, 2020 Share Posted May 30, 2020 Don't need to delete. You can just reply and say "oh, hey, by the way, figured it out, it was ___". Quote Link to comment https://forums.phpfreaks.com/topic/310864-retreiving-data-from-database-upon-change-of-textbox/#findComment-1578531 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.