Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-29-2009, 10:39 PM   PM User | #1
tommykent1210
New to the CF scene

 
Join Date: Oct 2009
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
tommykent1210 is an unknown quantity at this point
Login script simply wont work....

Ok, im quite new to php. I have a tutorial booklet that helped me code this, however it wont work, its supposed to redirect me to admincp.php when i successfully login, and redirect back to index when login fails. However it only ever redirects to index.


here:

index:
PHP Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<
title>mysite</title>
<
script language="javascript">
function 
Validate(){
    var 
username document.frmLogin.txtUsername.value;
    var 
lenusername username.length;
    var 
password document.frmLogin.txtPassword.value;
    var 
lenpassword password.length;
    if(
username <1) {
        
alert("Please enter your username.");
        
document.frmLogin.txtUsername.value "");
        return 
false;
    }
    else if(
lenpassword <1) {
        
alert("Please enter your passowrd.");
        
document.frmLogin.txtPassword.value "");
        return 
false;
    }
    else {
        
frmLogin.Submit.disabled true;
        return 
true;
    }
}
</script>
// ----------------------------------------------------------------------\
// Tom's Website                                                          |
// Copyright 2009 GFX-Core                                                  |
//                                                                          |
// Redistribution prohibited without written permission                      |
// ______________________________________________________________________/
</head>

<body>
<H3>My Website</h3>
<br/>
<table>
    <form name="frmLogin" action="login.php" method="post" onSubmit="return Validate()">
    <input type="hidden" value="agentlogin" />
    <tr>
        <td><input name="txtUsername" type="text" id="txtUsername" maxlength="30" />
        Username</td>
    </tr>
    <tr>
        <td><input name="txtPassword" type="password" id="txtPassword" maxlength="10" />
        Password </td>
     </tr>  
    <tr>
        <td><input type="submit" name="submit" value="Login" /></td>
    </tr>
    </form>
</body>
</html> 
Login.php:
PHP Code:
<?php
include("inc/config.php");

session_start();
header("Cache-control: private");
$username trim($_POST['txtUsername']);
$password trim($_POST['txtPassword']);
    if (
$username != "" && $password != "") {

//Connect to Database
     
$db mysql_connect("$dbhost, $dbuser, $dbpass");
     
mysql_select_db("$dbname, $db");
    
$sql "SELECT * FROM users WHERE username ='" .$username."'AND password ='" .$password."'";
    
$result mysql_query($sql);
//Count number of records
    
$num=mysql_num_rows($result);
    if(
$num==0){
            
//close DB
            
mysql_close();
            
//then redirect to index
            
header("Location: index.php");
    }
    else {
        
//login ok!
        
$_SESSION['ID'] = mysql_result($result,0,"ID");
        
//go to menu
        
header("Location: admincp.php");
    }
    
//close database
    
mysql_close();
}
    else{
        
$_SESSION['ID'] ="";
    
header("Location: index.php");
    }
?>
Herlp would be appreciated

Last edited by tommykent1210; 10-29-2009 at 11:53 PM..
tommykent1210 is offline   Reply With Quote
Old 10-29-2009, 11:09 PM   PM User | #2
Phil Jackson
Senior Coder

 
Join Date: Aug 2009
Location: Mansfield, Nottinghamshire, UK
Posts: 1,547
Thanks: 57
Thanked 148 Times in 147 Posts
Phil Jackson is on a distinguished road
$num=mysql_numrows($result);

to

$num=mysql_num_rows($result);

for a start
__________________
Website Design Mansfield
PHP Code:
function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
echo 
I_LOVE(); 
Phil Jackson is offline   Reply With Quote
Old 10-29-2009, 11:54 PM   PM User | #3
tommykent1210
New to the CF scene

 
Join Date: Oct 2009
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
tommykent1210 is an unknown quantity at this point
ok, fixed. still doesnt solve the probelm... Is the include config.php file bit correct?
tommykent1210 is offline   Reply With Quote
Old 10-29-2009, 11:57 PM   PM User | #4
_Aerospace_Eng_
Supreme Master coder!


 
_Aerospace_Eng_'s Avatar
 
Join Date: Dec 2004
Location: In a place far, far away...
Posts: 19,293
Thanks: 2
Thanked 1,044 Times in 1,020 Posts
_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light
This is wrong
PHP Code:
$db mysql_connect("$dbhost, $dbuser, $dbpass");
     
mysql_select_db("$dbname, $db"); 
It should be
PHP Code:
$db mysql_connect($dbhost$dbuser$dbpass);
     
mysql_select_db($dbname$db); 
Learn to follow the tutorial better. I doubt it told you to put all of those in quotes. Also there is a of other stuff wrong. The main thing I see is you aren't protecting yourself from mysql_injection and sooner or later you site will likely get hacked.

http://www.tizag.com/mysqlTutorial/m...-injection.php
__________________
||||If you are getting paid to do a job, don't ask for help on it!||||
_Aerospace_Eng_ is offline   Reply With Quote
Old 10-29-2009, 11:58 PM   PM User | #5
Phil Jackson
Senior Coder

 
Join Date: Aug 2009
Location: Mansfield, Nottinghamshire, UK
Posts: 1,547
Thanks: 57
Thanked 148 Times in 147 Posts
Phil Jackson is on a distinguished road
dont know... change it to

PHP Code:

$dir 
"inc/config.php";
if(
file_exists($dir))
{
    include(
$dir);
}
else
{
    echo 
"dir does not exist";

__________________
Website Design Mansfield
PHP Code:
function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
echo 
I_LOVE(); 
Phil Jackson is offline   Reply With Quote
Old 10-29-2009, 11:59 PM   PM User | #6
Phil Jackson
Senior Coder

 
Join Date: Aug 2009
Location: Mansfield, Nottinghamshire, UK
Posts: 1,547
Thanks: 57
Thanked 148 Times in 147 Posts
Phil Jackson is on a distinguished road
change

PHP Code:
$result mysql_query($sql); 
to

PHP Code:
$result mysql_query($sql) or die("Error: ".mysql_error()); 
__________________
Website Design Mansfield
PHP Code:
function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
echo 
I_LOVE(); 
Phil Jackson is offline   Reply With Quote
Old 10-30-2009, 12:15 AM   PM User | #7
tommykent1210
New to the CF scene

 
Join Date: Oct 2009
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
tommykent1210 is an unknown quantity at this point
It seems that it wont connect to the mysql. It says;

Code:
Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'nobody'@'10.50.0.58' (using password: NO) in /home/a9541859/public_html/mysite/login.php
yet the password is being used, it just doesnt seem to recognise it....
tommykent1210 is offline   Reply With Quote
Old 10-30-2009, 12:17 AM   PM User | #8
tommykent1210
New to the CF scene

 
Join Date: Oct 2009
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
tommykent1210 is an unknown quantity at this point
then:
Code:
Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host 'MYWEBHOSTMYSQL, MYSQLUSERNAME, PASSWORD' (3) in /home/a9541859/public_html/mysite/login.php
obviously i have removed my details
tommykent1210 is offline   Reply With Quote
Old 10-30-2009, 12:20 AM   PM User | #9
Phil Jackson
Senior Coder

 
Join Date: Aug 2009
Location: Mansfield, Nottinghamshire, UK
Posts: 1,547
Thanks: 57
Thanked 148 Times in 147 Posts
Phil Jackson is on a distinguished road
("$dbhost, $dbuser, $dbpass");

to


($dbhost, $dbuser, $dbpass);
__________________
Website Design Mansfield
PHP Code:
function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
echo 
I_LOVE(); 
Phil Jackson is offline   Reply With Quote
Old 10-30-2009, 12:26 AM   PM User | #10
tommykent1210
New to the CF scene

 
Join Date: Oct 2009
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
tommykent1210 is an unknown quantity at this point
Ah-ha! that worked, thanks better correct this book then lol, written for A-level and ive found 3 mistakes already
tommykent1210 is offline   Reply With Quote
Old 10-30-2009, 12:37 AM   PM User | #11
Phil Jackson
Senior Coder

 
Join Date: Aug 2009
Location: Mansfield, Nottinghamshire, UK
Posts: 1,547
Thanks: 57
Thanked 148 Times in 147 Posts
Phil Jackson is on a distinguished road
no worries
__________________
Website Design Mansfield
PHP Code:
function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
echo 
I_LOVE(); 
Phil Jackson is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 02:44 PM.


Advertisement
Log in to turn off these ads.