Note that there are some explanatory texts on larger screens.

plurals
  1. POJquery, ajax post and get results?
    primarykey
    data
    text
    <p>I am making a login, I want ajax to post each key stroke to the query. When the login matches a login in the database (mySQL), I want the password to be returned back to the parent page. That is all for now. I have in the past used ajax to post php to databases, but never had to return a variable back. I also do not know if I am passing the form info over, thanks!</p> <p>index.php script:</p> <pre><code>$(function(){ $("#inputEmail").keyup(function() { var UsernameInput = $(this).val(); $.ajax({ type: "POST", url: "PullUserDb.php", data: { 'UsernameInput':UsernameInput }, dataType: "text", success: function(data) { $('.body').html(data); } }); }); }); </code></pre> <p>index.php HTML:</p> <pre><code> &lt;div class = "HeaderLogin"&gt; &lt;form class="LoginForm"&gt; &lt;div class="control-group"&gt; &lt;div class="controls"&gt; &lt;input style = "height: 30px" type="text" id="inputEmail" placeholder="Email"&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="control-group"&gt; &lt;div class="controls"&gt; &lt;input style = "height: 30px" type="password" id="inputPassword" placeholder="Password"&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="control-group"&gt; &lt;div class="controls"&gt; &lt;button style = "width: 200px" type = "button" class="SubmitLogin"&gt;Sign in&lt;/button&gt; &lt;/div&gt; &lt;/div&gt; &lt;/form&gt; &lt;/div&gt; </code></pre> <p>PullUserDb.php:</p> <pre><code>&lt;?php //Connect to the server $db_server = mysql_connect('localhost','root',''); if(!$db_server) die("Unable to connect to MySQL: " . mysql_error()); ?&gt; &lt;?php //Connect to the database mysql_select_db('databases') or die("Unable to select database: " . mysql_error()); ?&gt; &lt;?php $Input_Username = $_POST['UsernameInput']; //Pull columns and store them into variables $query_users = "Select * FROM users WHERE Username = '".$Input_Username."'"; $result_users = mysql_query($query_users); if (!$result_users) die ("Database access failed: " . mysql_error()); while($row_user_fetch = mysql_fetch_array($result_users)) { $Username = $row_users_fetch['Username']; $Password = $row_users_fetch['Password']; $Email = $row_users_fetch['Email']; echo $Email; } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload