RE: Re: hlp regarding Registration Form

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I wrote a bunch of code which deals with this problem, but it's too much to
post here. There are simple things you can do to clean up your code.
As things get complicated, you will find that a simple OOP system which
validates at the database entry level, not at the page level will save you a
LOT of work. In other words,  it will take a bit more code, but your life
will be infinitely easier in the long-run. 

Why are you using JS with a simple test like this? It doesn't make a lot of
sense, when all you need to do is echo the cleaned-up $_POST['cname'] as
part of the message output. 

So, if I read your code correctly I would start the re-write as follows
(placing all code at the top of the page instead of sprinkling it through
the page making your colleague have to hunt for it). You might have to fix
function names, etc., but you get the idea:
____________________________________________________________________________
____________________

function testRequest()
{
// you don't need full quotes if there's nothing for PHP to interpret
$msg='';

	// you can put functions within functions without using classes!
	function  doDBQuery($_REQUEST)
	{
		// clean up $_REQUEST input

		//run DB query, ideally through another function not raw
like this.
		$query="select * from tblusers where username='".$name."'"; 
		$result=mysql_query($query);

		//return results simply
		if(mysql_num_rows($result)==0) {RETURN true; }
	}

//this is simple, clean and effective for one-step IF/ELSE loops
// what was with all the concats anyway?? You don't need them.
//if you clean the user input, why not just echo it here instead of using
JS??
$msg .=  (doDBQuery()) ? "<font color='red'>User ID {cleaned up cname} is
available!</font>" : "<font color='green'>User ID {cleaned up cname} is not
available!</font>";

return $msg; 
} 
?> 
<script language=javascript>
function checkuser()
{
name=document.registrationfrm.cname.value;
display.innerHTML="<?php $name='"+name+"'; test($name);?>"; 
} 
</script> 
<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'><?php print testRequest(); ?> </h6>

</form> 
</body>
____________________________________________________________________________
____________________

-----Original Message-----
From: php-objects@xxxxxxxxxxxxxxx [mailto:php-objects@xxxxxxxxxxxxxxx] On
Behalf Of sam_sjc_2k4
Sent: Wednesday, August 16, 2006 10:24 PM
To: php-objects@xxxxxxxxxxxxxxx
Subject:  Re: hlp regarding Registration Form

Hi Francis,

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.

here is my code:

registration.php
---------------
<?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);?>"; } </script>
</form> </body>

Thanks,
Danny.






PHP Data object relational mapping generator http://www.metastorage.net/
Yahoo! Groups Links



 








PHP Data object relational mapping generator
http://www.metastorage.net/ 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/php-objects/

<*> To unsubscribe from this group, send an email to:
    php-objects-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 




[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux