jquery - (细节错误求教)PHP+AJAX交互判断用户名是否存在
<code>html代码输入框:<input type="text" class="form-control" name="username" id="username" placeholder="请输入用户名" required autofocus="on" onblur="chkname();"> js检测(仅列出jquery判断用户名的代码): $(document).ready(function(){ //判断用户名是否已经注册了 $('#username').blur(function() { if ($('#username').val() != '') { $.post('chkname.php', {username : $('#username').val()}, function(data) { if (data == 0) { $('#notice1').html('抱歉,该用户名已经被占用!').css('color', 'red'); } else { $('#notice1').html('该用户名可以被注册!').css('color', '#00FFEC'); } }); } }); //验证邮箱密码等信息 $('#submit').click(function(){ //验证邮箱的格式和信息 if($('#username').val()=='') { $('#notice1').html("用户名不能为空!").css('color','red'); return false; } )}; php端代码:chkname.php(根据后台其他功能显示判定smarty模板已经生效,且数据库连接正确) <?php session_start(); header("Content-type:text/html;charset=utf-8"); require_once("system/system.inc.php"); if (isset($_POST['username'])) { $sql="select * from admin_users where username=$_POST['username']"; $re=mysql_query($sql); if (is_array($re)) { echo 0; //用户不合法 exit; } if ($re == 0) { echo 1; //用户合法 exit; } } SQL端:数据库名db_smartytest 其中一表admin_users,(user_id,user_name,user_pass)user_name中存了一个数据ceshi 检测时在用户名中输入ceshi没有起到PHP+AJAX交互判断用户名是否存在的功能,检查两遍不知错误出现 在哪里,希望高手帮忙看看,谢谢 </code></code>
回复内容:
<code>html代码输入框:<input type="text" class="form-control" name="username" id="username" placeholder="请输入用户名" required autofocus="on" onblur="chkname();"> js检测(仅列出jquery判断用户名的代码): $(document).ready(function(){ //判断用户名是否已经注册了 $('#username').blur(function() { if ($('#username').val() != '') { $.post('chkname.php', {username : $('#username').val()}, function(data) { if (data == 0) { $('#notice1').html('抱歉,该用户名已经被占用!').css('color', 'red'); } else { $('#notice1').html('该用户名可以被注册!').css('color', '#00FFEC'); } }); } }); //验证邮箱密码等信息 $('#submit').click(function(){ //验证邮箱的格式和信息 if($('#username').val()=='') { $('#notice1').html("用户名不能为空!").css('color','red'); return false; } )}; php端代码:chkname.php(根据后台其他功能显示判定smarty模板已经生效,且数据库连接正确) <?php session_start(); header("Content-type:text/html;charset=utf-8"); require_once("system/system.inc.php"); if (isset($_POST['username'])) { $sql="select * from admin_users where username=$_POST['username']"; $re=mysql_query($sql); if (is_array($re)) { echo 0; //用户不合法 exit; } if ($re == 0) { echo 1; //用户合法 exit; } } SQL端:数据库名db_smartytest 其中一表admin_users,(user_id,user_name,user_pass)user_name中存了一个数据ceshi 检测时在用户名中输入ceshi没有起到PHP+AJAX交互判断用户名是否存在的功能,检查两遍不知错误出现 在哪里,希望高手帮忙看看,谢谢 </code></code>
<code>php</code><code> //建议使用pdo $sql="select * from admin_users where username='".$_POST['username']."'"; $re=mysql_query($sql); if (mysql_num_rows($re) == 0) { echo 1; //用户合法 exit; } esle { echo 0; //用户不合法 exit; } </code>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.
