Wrox Programmer Forums
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 24th, 2006, 01:47 AM
Authorized User
 
Join Date: Oct 2005
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Default NEWBIE HELP

Hi,

I generally script in ASP but I have a friend who needs a simple login script. I was wondering if someone could show me how to re-write my script in php.

Code:
Dim conn, sql, filepath
Set conn = Server.CreateObject("ADODB.Connection")
FilePath = "C:\inetpub\wwwroot\sample\cig-bin\test.mdb"

SQL = "SELECT * FROM ADMIN WHERE "
SQL = SQL & "Username ='" & request.form("txtuser") & "' "
SQL = SQL & "AND Pword ='" & request.form("txtpword") & "';"

set rsTemp = conn.execute (SQL)

If Not rsTemp.EOF Then
  'Login action
Else
  'Bad login action
End If

rsTemp.Close
Set rsTemp = Nothing

conn.Close
Set conn = Nothing
Can someone convert this to php?

 
Old May 24th, 2006, 06:41 AM
Friend of Wrox
 
Join Date: Dec 2003
Posts: 488
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Okey dokey, I don't have msaccess here (check http://uk.php.net/odbc_connect for odbc stuff)

This is the would do the same thing if you were connecting to a mysql database:

<?php
// stuff we need from the request
$txtuser = $_REQUEST['txtuser'] ;
$txtpword = $_REQUEST['txtpword'];

// set up our db connection
$db = mysql_connect("localhost", "username", "password");
mysql_select_db("database_name",$db) || die("Problem connecting to database");

// get our SQL ready
$sql = "SELECT * FROM ADMIN WHERE ";
$sql .= "username='$txtuser' AND password='$txtpword'";

// run the query
$results = mysql_query($sql);

// do stuff according to what cam back
if (mysql_num_rows($results)==1 && $results)
   login_action();
else
   auth_error();
?>

Cheers
Charlie

--
Don't Stand on your head - you'll get footprints in your hair
                                           http://charlieharvey.org.uk
                                              http://charlieharvey.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Please help the newbie!! shelly.aix Visual Basic 2008 Essentials 2 December 16th, 2008 07:35 AM
Newbie help... mkruger XSLT 7 October 24th, 2007 02:33 AM
Newbie here jmac731976 HTML Code Clinic 13 August 29th, 2007 03:54 PM
Newbie please help indyanguy XSLT 1 September 2nd, 2005 09:18 AM
Newbie Help! TheShadow Javascript 1 March 21st, 2005 03:42 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.