|
Posted by J.O. Aho on 08/16/06 14:31
Danny wrote:
> Hi Mark,
>
> Thnx 4 the hlp. But i already have the submit button which will
> invoke the register.php page...thats y i used a button which invokes
> javascript function(i know i'm complicating myself!)...which inturn
> invokes PHP function!!!...pls hlp me to simplify my code.
PHP is server side script language, JavaScript is client side script language,
this makes that you must _submit_ the data back to the server before PHP can
do with any data that the JavaScript generates. PHP can create a dynamic
JavaScript.
> here is my code:
>
> <?php
> include_once "siteincludes.php";
> require_once "dbconnect.php";
> function test($name)
> {
> $msg="";
> $query="select * from tblusers where username='".$name."'";
> $result=mysql_query($query);
> if(mysql_num_rows($result)==0)
> {
> $msg="<font color='green'>"."User ID is not available!"."</font>";
> }
> else
> {
> $msg="<font color='red'>"."User ID is available!"."</font>";
> }//end of else
> echo $msg;
> }
> ?>
> <body>
> <form name="registrationfrm" action="register.php" method="post">
> User ID:<input type="text" name="cname">
> <button onclick="checkuser()">Check Availability!</button>
> <h6 id='display' name='display'></h6>
> <script language=javascript>
> function checkuser(){
> name=document.registrationfrm.cname.value;
> display.innerHTML="<?php $name='"+name+"'; test($name);?>";
The <?php $name='"+name+"'; test($name);?> is processed when the page is
generated, and the value submitted to the function test() is "+name+", so you
could shorten down the php code and just have <?php test('"+name+"'); ?>.
//Aho
Navigation:
[Reply to this message]
|