Forums

PHP

This topic is locked

verification

Posted 21 Aug 2001 15:44:52
1
has voted
21 Aug 2001 15:44:52 Keith Slater posted:
Hey I need a way to have verification. What I want to happen is when some one types in their name I want it to go to carry the varriables to the next screen but I also want it to verify that that name is in the database. What would be the easiest way to do this??

thanks!

Keith Slater

Replies

Replied 21 Aug 2001 23:26:38
21 Aug 2001 23:26:38 Bruno Mairlot replied:
Hi,

Here is my suggestion :

So you've got a form with (let's suppose) an input named UserName ok ?

The action of the form of this page should be an intermediary page which won't print anything but will redirect to what you call "the next screen" that will be effectively the next screen the user will see.

Depending on the result of the query looking for the name of the user, you take different action.

Let's suppose you have the following page :

- userinfo.html (the one with the form tag)
- nextscreen.php (the so-called next screen).

Between these two files you insert the page check.php so you have :
<pre id=code><font face=courier size=2 id=code>
userinfo.html -&gt; check.php -&gt; nextscreen.php
-&gt; otherscreen.php
</font id=code></pre id=code>

Where otherscreen.php is the page that the user sees if its name isn't into the database.

Here is the code I'd suggest for check.php (Without error handling and the Database part is pure MySQL, but the design is the same for anything...).

<b>Take care to put the &lt;?php at the very first line of code</b> otherwise PHP will complain that it has already sent headers and cannot rewrite them.

The red code is the important one. Change anything you want, but the important is 1) Encode the URL to use a GET request with the parameter 2) Redirect before having printed anything


---- check.php ----
<pre id=code><font face=courier size=2 id=code>
&lt;?php

/* Connection to database */
$dbh=mysql_connect(.......);
mysql_select_db('yourDB');

$query="SELECT UserName from UserTable WHERE UserName='$UserName'";
$res=mysql_query($query,$dbh);
if(!$res){
/* Oups query didn't work */
}
else{
$numrows=mysql_num_rows($res);
if($numrows==1){
/* User exists and is unique */
<font color=red>$url=urlencode("nextscreen.php?UserName=$UserName";</font id=red>

}
else if($numrows==0){
/* User doesn't exists */
<font color=red>$url=urlencode("otherscreen.php?UserName=$UserName";</font id=red>
}
else {
/* User exists but is not unique */
/* Redirect or do whatever...*/
$url='/';
}<font color=red>
header("Status: 302 Moved";
header("Location: $url";</font id=red>

}

?&gt;

</font id=code></pre id=code>

This solution might have a problem though, if UserName is longer thant 4096 chars, because the "next screen" the user will see will be requested by a GET method, and you can't use more than 4096 chars for a GET request. So if you set maxsize of UserName in userinfo.html less than that, it should be ok.


"First they laugh at you, then they fight you, then you Win..." Ghandi
Replied 22 Aug 2001 01:13:35
22 Aug 2001 01:13:35 Tim Green replied:
Maehdros,

I completely agree with your answer, but please this is a UD group, and you should therefore use the UD/PHP Syntax for DB Connections so as not to confuse newbies.

That means NO mysql_connect's please, as the PHP Server Model is DB independant, so should any DB code you post here. It minimizes confusion, and saves us having to answer the same question, amending it so it is applicable for different DBMS.

Tim Green

Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>
Replied 22 Aug 2001 10:48:50
22 Aug 2001 10:48:50 Bruno Mairlot replied:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
Maehdros,

I completely agree with your answer, but please this is a UD group, and you should therefore use the UD/PHP Syntax for DB Connections so as not to confuse newbies.

<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>

The only reason I don't do it that way, it's because I doesn't know how to do it <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>

But I'll try to study the code so that I could repeat it...

But neverthless, if your DB connection is DB independant, you can't deny that SQL syntax differs a lot from one server to another...

How should I then write query example ?

"First they laugh at you, then they fight you, then you Win..." Ghandi
Replied 22 Aug 2001 14:45:08
22 Aug 2001 14:45:08 Tim Green replied:
You raise a valid point about the SQL syntax. However, the SQL you have written in the above example is standard SQL Syntax and is recognizeable by all DBMS, so the problem (in this instance) doesn't exist.

I appreciate that you don't know the command set used by UD, but it really is worth learning the Server Behaviour usage in UD as it has a major inluence on workflow.

In your above example, you can probably get away with using 2 Server Behaviours and a couple of lines of handcoding.

However, if this kind of validation is something that will be used alot, then writing a custom Server Behaviour will probably solve the problem more succinctly.

I know that there are already a number of different coding styles in existence for PHP already, and learning another one might (initially) appear to be a waste of time. However, as this whole site is based around UltraDev, it really is going to pay dividends if you get aquanted with it, sooner rather than later.

Tim Green

Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>
Replied 22 Aug 2001 22:38:55
22 Aug 2001 22:38:55 Bruno Mairlot replied:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
I know that there are already a number of different coding styles in existence for PHP already, and learning another one might (initially) appear to be a waste of time. However, as this whole site is based around UltraDev, it really is going to pay dividends if you get aquanted with it, sooner rather than later.
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>

I agree with you. I love UD and all that comes with it, but I have two complains :

- It crashes extremely often (I've the 4.01 patch)
- The code produced isn't optimized at all. Which in itself is ok. But what is not, it's that if you touch this code, you lose almost every interest in UD, I mean the ability to design it quit easyli with drop-down menus,...and so on.

The true difference between UltraDev and a true RAD developpment tool like Delphi, is that UD doesn't understand anything to the code it produce (not talking about HTML, but PHP or ASP)...It can't definitevely not handle any modifications you make to the code.

It has been some time since I'm thinking of embedding the PHP server code source into DW to make it able to pa_rse the HTML/PHP code.

Then we could develop a full-feature API that could allow us to create extraordinary extension to keep track of all of our modification and hand coding.

Do you Imagine what you could do with such a feature ??

But I'm a little off-topic...

"First they laugh at you, then they fight you, then you Win..." Ghandi
Replied 23 Aug 2001 15:13:29
23 Aug 2001 15:13:29 Keith Slater replied:
Soo.. did we ever come of with a solution in UD?

Keith Slater

Reply to this topic