Register and Login (Email Activation) jQuery
Posted: Thu Jul 07, 2011 8:01 pm
Ok I have been following a tutorial from another site on how to jQuery/AJAX your input data so it checks if a username has been used or not. All is working great (so far) but in the included PHP file that connects to the DB and runs the SQL check I have entered the connection details, so I thought to tidy this up I will use the init.inc.php that I made in the login tutorial from here. One problem, when I include that file instead of putting the database details directly in it doesn't work. It connects to the DB fine no errors, it just doesn't return any results via jQuery. Any ideas?
Register.php
[syntax=php]<head>
<meta http-equiv="Content-Type" content="text/html; charset+utf-8" />
<link rel="stylesheet" type="text/css" href="ext/css/style.css" />
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$ (document).ready(function() {
$('#username_feedback').load('../../core/inc/register_checks.inc.php').show();
$('#username').keyup(function(){
$.post('../../core/inc/register_checks.inc.php', { username: user_register.username.value },
function(result) {
$('#username_feedback').html(result).show();
});
});
});
</script>
<title><?php echo $page_title ?></title>
</head>
<body>
<div>
<?php
if (empty($errors) === false) {
?>
<ul>
<?php
foreach ($errors as $error){
echo "<li>{$error}</li>";
}
?>
</ul>
<?php
}
?>
</div>
<form name="user_register" action="" method="post">
<p>
<label for"username">Username:</label>
<input type="text" name="username" id="username" value="<?php if (isset($_POST['username'])) echo htmlentities($_POST['username']); ?>">
<div id="username_feedback"></div>[/syntax]
register_checks.php WORKING
[syntax=php]<?php
mysql_connect('localhost', 'root', '');
mysql_select_db('advertise');
$username = mysql_real_escape_string($_POST['username']);
$check = mysql_query("SELECT user_name FROM users WHERE user_name='$username'");
echo $check_num_rows = mysql_num_rows($check);
?>[/syntax]
register_checks.php NOT WORKING
[syntax=php]<?php
include('../init.inc.php');
$username = mysql_real_escape_string($_POST['username']);
$check = mysql_query("SELECT user_name FROM users WHERE user_name='$username'");
echo $check_num_rows = mysql_num_rows($check);
?>[/syntax]
I changed some database details around in the init.inc.php file and I was getting errors back in my register.php file about connecting to the DB so the register_checks.php is using the init.inc.php file to 'import' the DB credentials just for some reason its not outputting my SQL query.
Register.php
[syntax=php]<head>
<meta http-equiv="Content-Type" content="text/html; charset+utf-8" />
<link rel="stylesheet" type="text/css" href="ext/css/style.css" />
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$ (document).ready(function() {
$('#username_feedback').load('../../core/inc/register_checks.inc.php').show();
$('#username').keyup(function(){
$.post('../../core/inc/register_checks.inc.php', { username: user_register.username.value },
function(result) {
$('#username_feedback').html(result).show();
});
});
});
</script>
<title><?php echo $page_title ?></title>
</head>
<body>
<div>
<?php
if (empty($errors) === false) {
?>
<ul>
<?php
foreach ($errors as $error){
echo "<li>{$error}</li>";
}
?>
</ul>
<?php
}
?>
</div>
<form name="user_register" action="" method="post">
<p>
<label for"username">Username:</label>
<input type="text" name="username" id="username" value="<?php if (isset($_POST['username'])) echo htmlentities($_POST['username']); ?>">
<div id="username_feedback"></div>[/syntax]
register_checks.php WORKING
[syntax=php]<?php
mysql_connect('localhost', 'root', '');
mysql_select_db('advertise');
$username = mysql_real_escape_string($_POST['username']);
$check = mysql_query("SELECT user_name FROM users WHERE user_name='$username'");
echo $check_num_rows = mysql_num_rows($check);
?>[/syntax]
register_checks.php NOT WORKING
[syntax=php]<?php
include('../init.inc.php');
$username = mysql_real_escape_string($_POST['username']);
$check = mysql_query("SELECT user_name FROM users WHERE user_name='$username'");
echo $check_num_rows = mysql_num_rows($check);
?>[/syntax]
I changed some database details around in the init.inc.php file and I was getting errors back in my register.php file about connecting to the DB so the register_checks.php is using the init.inc.php file to 'import' the DB credentials just for some reason its not outputting my SQL query.