Webmaster Forum


Go Back   Webmaster Forum > Web Development > Web Design Lobby > Coding Forum
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Coding Forum Problems with your code? Let's hear about it.

Bidding Directory   1,000 Directory Submissions   V7N Directory

Reply
 
LinkBack Thread Tools Display Modes
Old 02-25-2008, 02:20 PM   #1 (permalink)
Junior Member
 
Join Date: 01-14-08
Posts: 10
iTrader: 0 / 0%
Latest Blog:
None

birdbrain24 is liked by many
Ajax & PHP: On the same page?

Ok i just started learning ajax and i was wondering if i can have the ajax and the php on the same page?

Here's my pages:
register.html
registercheck.php

register.html
Code:
<html> <head> <title>Register</title> <script language="javascript" type="text/javascript"> <!-- //Browser Support Code function checkusername(){ var ajaxRequest; // The variable that makes Ajax possible! try{ // Opera 8.0+, Firefox, Safari ajaxRequest = new XMLHttpRequest(); } catch (e){ // Internet Explorer Browsers try{ ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ // Something went wrong alert("Your browser do not support ajax!"); return false; } } } // Create a function that will receive data sent from the server ajaxRequest.onreadystatechange = function(){ if(ajaxRequest.readyState == 4){ var ajaxDisplay = document.getElementById('username_div'); ajaxDisplay.innerHTML = ajaxRequest.responseText; } } var username = document.getElementById('username').value; var query = "?username=" + username; ajaxRequest.open("GET", "registercheck.php" + query, true); ajaxRequest.send(null); } //--> </script> </head> <body> <form> <table border="1" bordercolor="#000000" cellspacing="0"> <tr> <td>Username:</td> <td><input type="text" id="username" onkeyup="checkusername()" /></td> <td><div id="username_div">Username Status!</div></td> </tr> </table> </form> </body> </html>
registercheck.php
PHP Code:
<?php
$dbhost 
"localhost";
$dbuser "root";
$dbpass "";
$dbname "race";
    
//Connect to MySQL Server
mysql_connect($dbhost$dbuser$dbpass);
    
//Select Database
mysql_select_db($dbname) or die(mysql_error());
    
//Set variables
$username $_GET['username'];
    
//Mysql Variables
$result_query mysql_query("SELECT * FROM `users` WHERE `username`='$username'") or die(mysql_error());
$result_num_rows mysql_num_rows($result_query);

  if(isset(
$username)):
  
    if(
$result_num_rows == 0):
    
    echo 
'<font color="green"><strong>Username avaliable!</strong></font>';
    
    elseif(
$result_num_rows != 0):
    
    echo 
'<font color="red"><strong>Username unavaliable!</strong></font>';
    
    endif;
    
  endif;
?>
I hope someone could help! Thanks anyways!
birdbrain24 is offline  
Add Post to del.icio.us
Reply With Quote
Sponsored Links
SEO Hosting by HostGator  Advertise Here  Buy Blog Links
Old 02-25-2008, 02:45 PM   #2 (permalink)
Junior Member
 
Join Date: 01-14-08
Posts: 10
iTrader: 0 / 0%
Latest Blog:
None

birdbrain24 is liked by many
solved!
birdbrain24 is offline  
Add Post to del.icio.us
Reply With Quote
Go Back   Webmaster Forum > Web Development > Web Design Lobby > Coding Forum

Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Add AJAX to my PHP MySQL page? birdbrain24 Coding Forum 1 01-17-2008 05:38 AM
Google Ajax Powered 404 Page Jeffro2pt0 Blogging Forum 2 09-25-2007 07:45 AM
AJAX: bots hitting AJAX scripts kkiely Coding Forum 1 04-21-2007 01:14 AM
AJAX in IE7 help SasaVtec Coding Forum 1 01-12-2007 11:53 AM
AJAX Bredd S Webmaster Revenue 4 08-09-2006 12:59 PM


Sponsor Links
Get exposure! Get exposure! Find Scripts Web Hosting Directory Get exposure! SEO Blog


All times are GMT -7. The time now is 06:52 PM.
© Copyright 2008 V7 Inc