Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_php thread: How to???


Message #1 by guru@i... on Wed, 1 Aug 2001 04:51:39
Pardon me, I made a mistake....the following is what it should be

Username Generation
UPDATE guests SET UserID = CONCAT(left(FirstName,1),LastName)


Password Generation
UPDATE guests SET Password =left(md5(CONCAT(UserID,FirstName,LastName)),6);

I would like to convert the above sql instruction into php so that i can 
execute  a simple function and the username and password are generated for 
those records without one already assigned.

Thanks for any help/ideas etc etc




> Here is one point of view.  I made some changes to your variables.  I do 
not
> believe you wnat to generate two password with different criteria and 
placing
> there into the same field.
> 
> mysql_select_db($database) or die("Unable to select $datbase");
> 
> $username = left(md5(CONCAT(UserID,FirstName,LastName)),6);
> $query1="SELECT Username FROM guests";
> $link1 = mysql_query($updStmt) or die("<br><b><center><font 
color=red>Problem
> with guests table!</b></center><br> error-"
> . mysql_error() . "<br>\nquery - $query1</font>");
>  if ($myuser = mysql_fetch_array($query1))
>  {
>  $user = $myuser["Username"];
> }
> if ($user != $null){
> echo ("You already have that User Name on file!");
> exit();
> }
> 
> $addStmt="INSERT INTO guests (Username) VALUES ($username)";
> $link1 = mysql_query($addStmt) or die("<br><b><center><font 
color=red>Problem
> with Update of Username!</b></center><br> error-"
> . mysql_error() . "<br>\nquery - $addStmt</font>");
> 
> $passwd = left(md5(sysdate()),6);
> $updStmt="UPDATE guests SET Password = $passwd WHERE Username = 
$username";
> $link1 = mysql_query($updStmt) or die("<br><b><center><font 
color=red>Problem
> with Update of Password!</b></center><br> error-"
> . mysql_error() . "<br>\nquery - $updStmt</font>");
> 
> My technique is not by any means conventional.  I am self taught and 
from an
> world of data base development.  But here is my intent.
> Step 1 generate the username
> Step 2 check if that username is already in guest table.  If not, insert 
into
> guest table.
> Step 3 generate password
> Step 4 update the guest table
> 
> Any suggestions on how to improve this code will be welcome.
> I hope this helps,
> 
> Richard D. Williams
> 
> guru@i... wrote:
> 
> > Ladies and Gentlemen, its been a while since I have visited this site
> > cause everything was fine until now...
> >
> > I have a dilemma, how do i convert the following Mysql into php code:
> >
> > Username Generation
> >
> > UPDATE guests SET Password = left(md5(sysdate()),6);
> >
> > Password Generation
> >
> > UPDATE guests SET Password =left(md5(CONCAT
(UserID,FirstName,LastName)),6);
> >
> > any ideas or suggestions would be greatly appreciated,
> >
> > thanks
> >
> > Elliott

  Return to Index