Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Searching a db for username and password.
Old 07-18-2004, 12:59 PM Searching a db for username and password.
andrewsco's Avatar
Super Talker

Posts: 130
Trades: 0
Hi. Iv been reading a few books on php recently but still have a few problems with stuff.

I have managed to create a page where someone can regisiter with username and pass, this goes into a database. I cant seem to find a script anywhere which is embedded into a form that will search the database for the info to verify whether they are a member or not.

I eventually would like something like the 'your account' section of this site. http://www.antionline.com/

I just cant get the script to search the database...its called 'contacts' and has 'username' and 'password' as its fields

Sorry for all the questions, but if someone could help then it would be appreciated

Andy
__________________
My Webpage:
Please login or register to view this content. Registration is FREE
andrewsco is offline
Reply With Quote
View Public Profile Visit andrewsco's homepage!
 
 
Register now for full access!
Old 07-18-2004, 01:05 PM
Unknown.

Posts: 1,693
Trades: 0
If you mean you want a login page which will check if the username and password that the user enteres is valid....

This tutorial should help..

http://www.phpfreaks.com/tutorials/40/5.php

-James
Dark-Skys99 is offline
Reply With Quote
View Public Profile
 
Old 07-18-2004, 01:25 PM
andrewsco's Avatar
Super Talker

Posts: 130
Trades: 0
Cheers. Not got time to look at it now, but I think that is exactly what I am loking for.

Thnx again

Andy
__________________
My Webpage:
Please login or register to view this content. Registration is FREE
andrewsco is offline
Reply With Quote
View Public Profile Visit andrewsco's homepage!
 
Old 07-19-2004, 11:15 AM
andrewsco's Avatar
Super Talker

Posts: 130
Trades: 0
Hi. I have read through the tutorial and it really helped. I only came across one problem, and that was with the script of lost password script. I followed this:

http://www.phpfreaks.com/tutorials/40/8.php

I have followed the whole tutorial, and the rest is fine, but when I use the lost_pw.html it says this error:

Quote:
Method Not Allowed
The requested method POST is not allowed for the URL /lost_pw.html.
Can anyone help with this problem? There are two other things that I would like to do that the tutorial doesnt cover, that is to have a page where the person can login and change thier password to one of thier choice, and the second is to have a 'remember me' feature, using cookies. If anyone can help with a script for this or another tutorial then that would be great.

Andy
__________________
My Webpage:
Please login or register to view this content. Registration is FREE
andrewsco is offline
Reply With Quote
View Public Profile Visit andrewsco's homepage!
 
Old 07-19-2004, 01:42 PM
Unknown.

Posts: 1,693
Trades: 0
I dont know why it aint working...If you followed the tutorial and named all the database fileds the same as it said..It should work..Worked fine for me

Now to change the pasword...

This should work..Its what I created to use with that tutorial...

If you save this as password.php

PHP Code:
<?php

session_start
();
if (!
session_is_registered("userid"))
{
header("Location: http://www.dark-skys.com/join");
exit;
}
else{

echo 
"<title>Change Password</title>";

echo 
"<form name='form' method='post' action='changepass.php'>
<p>New Password: <input type='text' name='pass'></p>
<input type='hidden' name='change' value='change'>
<p><input type='submit' name='Submit' value='Change'></p>
</form>"
;

}
?>
Now save this as changepass.php

PHP Code:
<? 
session_start
();


$connection=mysql_connect("localhost","username","password"); 
    
$db=mysql_select_db("database_name",$connection); 
    } 
switch(
$_POST['change']){ 
    default: include 
'password.php'
    break; 
     
    case 
"change"
    (
$_POST['userid']); 
    break; 

    if(!
$pass){ 
        echo 
"<strong><font color=red>Please enter a Password</font></strong><br />"
        include 
'password.php'
        exit(); 
}
 
     
$password $pass

    
$db_password md5($password); 
     
    
$sql mysql_query("UPDATE users SET PASSWORD='$db_password
                WHERE userid='
$userid'"); 
     
    
$subject "Dark-Skys Members: Password Changed"
    
$message "<font face='Verdana' size='3'>Hi $first_name, Your password has now been changed</br></br>
New Password: <b>
$pass</b></br>
Use this password to login in future</br></br>
Thanks!</br>
</br></br></font>"

     
    
mail($email_address$subject$message"From: \" Name \" <you@site.com>\nContent-Type: text/html; charset=iso-8859-1 X-Mailer: chfeedback.php 2.01");
    echo 
"Your Password has now been changed to <b>$pass</b></br></br>Auto-Logout : Please login using your new password</br>"
    include 
'login.htm'
session_destroy();

?>
Note. For this to work you will need to register their emailaddress and userid as a session variable in the login php file...

So something like..

PHP Code:
        $_SESSION['email_address'] = $email_address
        
session_register('userid'); 
        
$_SESSION['userid'] = $userid
        
session_register('username'); 
(depends on what you named the fields in the database..I think I changed mine)

Not to sure about the cookies..Still trying to learn this myself..But there should be someone else who should be able to help

Hope this helps

-James
Dark-Skys99 is offline
Reply With Quote
View Public Profile
 
Old 07-19-2004, 01:45 PM hi
Mooofasa's Avatar
Defies a Status

Posts: 1,611
Name: Michael (mik) Land
Location: England
Trades: 0
how do i do php and mysql and what r they?
im confused. R they better than html/dhtml?
Dark Plz reply ma email
Mooofasa is offline
Reply With Quote
View Public Profile Visit Mooofasa's homepage!
 
Old 07-19-2004, 02:00 PM
Unknown.

Posts: 1,693
Trades: 0
PHP allows you to so much more...

Such as create Dynamic content by selecting information from a MySQL database..

Yea..Way much better than html/dhtml

The general thing that php does is processes the page before the user sees it and creates all the html..So you can include things from a database..

So much it can do..

I have an Ebook on PHP & MySQL i can mail it you if you want?

-James
Dark-Skys99 is offline
Reply With Quote
View Public Profile
 
Old 07-19-2004, 02:05 PM hi
Mooofasa's Avatar
Defies a Status

Posts: 1,611
Name: Michael (mik) Land
Location: England
Trades: 0
plz, ill have a look at tose ebooks. Ty
Mooofasa is offline
Reply With Quote
View Public Profile Visit Mooofasa's homepage!
 
Old 07-19-2004, 02:06 PM hi
Mooofasa's Avatar
Defies a Status

Posts: 1,611
Name: Michael (mik) Land
Location: England
Trades: 0
im no good wit databases, i havent got a clue bout them. I jus use dhtml and html its easier lol. im sure those ebooks will tell me somet
Mooofasa is offline
Reply With Quote
View Public Profile Visit Mooofasa's homepage!
 
Old 07-19-2004, 06:31 PM
andrewsco's Avatar
Super Talker

Posts: 130
Trades: 0
Hi Dark-Skys99 thanks for the code. I still am having trouble with the database though. I forgot to include the.php file in the form action bit of the lost_pw.html file. So I added it, but now whenever I send my email it comes up with a problem like this:

Quote:
Parse error: parse error, unexpected T_STRING in /hsphere/local/home/andrewan/shore2sure.com/db.php on line 26
Do you have any idea what this is and how I can make it work?

Thanks

Andy

Oh...PS here is my code for lost_pw.html AND lostpw.php

HTML Code:
<form name="form1" method="post" action="lostpw.php">
  <table width="50%" border="0" cellspacing="0" cellpadding="4">
    <tr> 
      <td>Please enter your email address</td>
      <td><input name="email_address" type="text" id="email_address"></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input name="recover" type="hidden" id="recover" value="recover">
        <input type="submit" name="Submit" value="Recover My Password!"></td>
    </tr>
  </table>
</form>
and here is the other...

PHP Code:
<?
include 'db.php';

switch(
$_POST['recover']){
    default:
    include 
'lost_pw.html';
    break;
    
    case 
"recover":
    
recover_pw($_POST['email_address']);
    break;
}
function 
recover_pw($email_address){
    if(!
$email_address){
        echo 
"You forgot to enter your Email address <strong>Knucklehead</strong><br />";
        include 
'lost_pw.html';
        exit();
    }
    
// quick check to see if record exists    
    
$sql_check mysql_query("SELECT * FROM users WHERE email_address='$email_address'");
    
$sql_check_num mysql_num_rows($sql_check);
    if(
$sql_check_num == 0){
        echo 
"No records found matching your email address<br />";
        include 
'lost_pw.html';
        exit();
    }
    
// Everything looks ok, generate password, update it and send it!
    
    
function makeRandomPassword() {
          
$salt "abchefghjkmnpqrstuvwxyz0123456789";
          
srand((double)microtime()*1000000); 
          
$i 0;
          while (
$i <= 7) {
                
$num rand() % 33;
                
$tmp substr($salt$num1);
                
$pass $pass $tmp;
                
$i++;
          }
          return 
$pass;
    }

    
$random_password makeRandomPassword();

    
$db_password md5($random_password);
    
    
$sql mysql_query("UPDATE users SET password='$db_password' WHERE email_address='$email_address'");
    
    
$subject "Your Password at MyWebsite!";
    
$message "Hi, we have reset your password.
    
    New Password: 
$random_password
    
    [url]http://www.mywebsite.com/login.php[/url]
    
    Thanks!
    The Webmaster
    
    This is an automated response, please do not reply!"
;
    
    
mail($email_address$subject$message"From: MyDomain Webmaster<admin@mydomain.com>\nX-Mailer: PHP/" phpversion());
    echo 
"Your password has been sent! Please check your email!<br />";
    include 
'login_form.html';
}
?>
Thanks again guys for any help

Andy
__________________
My Webpage:
Please login or register to view this content. Registration is FREE

Last edited by andrewsco; 07-19-2004 at 06:34 PM..
andrewsco is offline
Reply With Quote
View Public Profile Visit andrewsco's homepage!
 
Old 07-19-2004, 07:27 PM
Unknown.

Posts: 1,693
Trades: 0
I have no idea whats wrong with the code..If you've copied it the same it should work..

Maybe its because you are using it so that lost_pw.html submits the data to lostpw.php..

Because the idea is you just goto lostpw.php and then the form should appear as it is included..
PHP Code:
include 'lost_pw.html'
So when you enter the emailaddress it will send the email then include the login form..

So all the time it stays as lostpw.php

So try changing lost_pw.html to..
HTML Code:
<html>
<head>
<title>Lost Password</title>
</head>

<body bgcolor="white" text="black" link="blue" vlink="purple" alink="red">

<form name="form" method="post">
<input type=hidden name="recover" value="recover"><p>If you have forgot your 
password enter your email below and your password shall be automatically reset 
and your new password mailed to you</p>
<p>Email <input type="text" name="email_address"></p>
<p><input type="submit" value="Send to me"></p>
</form>
<p>&nbsp;</p>
</body>
</html>
This is the only thing I can think of...

Hope this helps

-James
Dark-Skys99 is offline
Reply With Quote
View Public Profile
 
Old 07-19-2004, 07:39 PM
andrewsco's Avatar
Super Talker

Posts: 130
Trades: 0
no luck! I think I have changed every combination of stuff i can there. The problem seems to be with line 26 and the db.php file, as it wont bring up the actual text box from the html file. I really dont understand it, I followed the tutorial exactly. If anyone else can help I would appreciate it as i am tearing my hair out here!!!

Andy
__________________
My Webpage:
Please login or register to view this content. Registration is FREE
andrewsco is offline
Reply With Quote
View Public Profile Visit andrewsco's homepage!
 
Old 07-19-2004, 07:42 PM
Unknown.

Posts: 1,693
Trades: 0
ooo.. I think i get it now...

I read it wrong before

If you post the coding for the db.php file I might be able to solve it

-James
Dark-Skys99 is offline
Reply With Quote
View Public Profile
 
Old 07-19-2004, 07:45 PM
andrewsco's Avatar
Super Talker

Posts: 130
Trades: 0
PHP Code:
<? 
/*  Database Information - Required!!  */
/* -- Configure the Variables Below --*/
$dbhost '69.49.230.13';
$dbusername 'andrewa_contacts';
$dbpasswd '????????';
$database_name 'andrewa_contacts';

/* Database Stuff, do not modify below this line */

$connection mysql_pconnect("$dbhost","$dbusername","$dbpasswd"
    or die (
"Couldn't connect to server.");
    
$db mysql_select_db("$database_name"$connection)
    or die(
"Couldn't select database.");
?>

There you go. See what u can see that I have missed

Andy
__________________
My Webpage:
Please login or register to view this content. Registration is FREE
andrewsco is offline
Reply With Quote
View Public Profile Visit andrewsco's homepage!
 
Old 07-19-2004, 07:51 PM
Unknown.

Posts: 1,693
Trades: 0
I dont know why its saying error on line 26..when there isnt even 26 lines

Maybe if you change it to...

PHP Code:
<?php

$dbhost 
'69.49.230.13'
$dbusername 'andrewa_contacts'
$dbpasswd '????????'
$database_name 'andrewa_contacts'

$connection mysql_connect("$dbhost","$dbusername","$dbpasswd"
    or die (
"Couldn't connect to server."); 
     
$db mysql_select_db("$database_name"$connection
    or die(
"Couldn't select database."); 
?>
it might work by adding the php to the start also changing it to mysql_connect instead of mysql_pconnect

Hope this helps

-James
Dark-Skys99 is offline
Reply With Quote
View Public Profile
 
Old 07-19-2004, 07:59 PM
andrewsco's Avatar
Super Talker

Posts: 130
Trades: 0
thats what I dont understand, unless it means that db.php is causing an error on lostpw.php but I really dont know. If anyone can help with this then i will love you for ever! lol

Andy
__________________
My Webpage:
Please login or register to view this content. Registration is FREE
andrewsco is offline
Reply With Quote
View Public Profile Visit andrewsco's homepage!
 
Old 07-19-2004, 08:04 PM
Unknown.

Posts: 1,693
Trades: 0
Try this for db.php...

PHP Code:
<?php

$username 
"andrewa_contacts"
$password "PASSWORD"
$database "andrewa_contacts"

$connection=mysql_connect("69.49.230.13",$username,$password) or die ("Couldn't connect to server."); 
    
$db=mysql_select_db($database,$connection) or die("Couldn't select database.");  

?>
-James
Dark-Skys99 is offline
Reply With Quote
View Public Profile
 
Old 07-19-2004, 08:11 PM
andrewsco's Avatar
Super Talker

Posts: 130
Trades: 0
still the same error im afriad. I dont think it is a problem with db.php as I have used that script to connect to the database on the other pages I created in that tutorial, like register etc. I think maybe its a problem with lostpw.php? I really am confused

Andy
__________________
My Webpage:
Please login or register to view this content. Registration is FREE
andrewsco is offline
Reply With Quote
View Public Profile Visit andrewsco's homepage!
 
Old 07-19-2004, 08:20 PM
andrewsco's Avatar
Super Talker

Posts: 130
Trades: 0
That last one did work! I forgot to edit PASSWORD to the actual password!!! lol Thank you for this post and the ebook

I am looking into sessions and cookies as well and want to add this feature to the whole lot. I havent read it yet but this looks like a good tutorial:

http://www.phpfreaks.com/tutorials/120/1.php

Andy
__________________
My Webpage:
Please login or register to view this content. Registration is FREE
andrewsco is offline
Reply With Quote
View Public Profile Visit andrewsco's homepage!
 
Old 07-19-2004, 08:30 PM
Unknown.

Posts: 1,693
Trades: 0
Glad it worked

Yea that tutorial is quite good..I used that myself for learning a little about cookies

-James
Dark-Skys99 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Searching a db for username and password.

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.60498 seconds with 12 queries