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
problem connecting login script to sql db
Old 04-29-2010, 10:26 PM problem connecting login script to sql db
Junior Talker

Posts: 1
Name: jera
Trades: 0
Hi everyone,

I am a newbie in web design, i am stuck at this login script.

In my main page, i have this code as my login:
Code:
<form action="cp.php" method="post">
              <img src="../../../../Desktop/for web/for web here/login.png" width="170" height="60" /> Username:
<label>
                <input name="username" value="" type="text" />
              </label>
              <label>Password:
                <input name="password" value="" type="password" />
              </label>
              <p>
                <input name="login" value="Sign In" type="submit" id="login" />
              </p>
            </form>
As you see it will go to my cp.php, in cp.php i have attached mysql dc infomation:

Code:
<?php
    
//Include the required file
    if(file_exists('config.php')){
        require_once("config.php");
        $session->stop();
    }
    
//The Ajax function
    echo "    <script language=\"javascript\" type=\"text/javascript\">
            <!-- 
            function ajaxFunction(url, div, menu, addon){
                var ajaxRequest;
                try{
                    ajaxRequest = new XMLHttpRequest();
                } catch (e){
                    try{
                        ajaxRequest = new ActiveXObject(\"Msxml2.XMLHTTP\");
                    } catch (e) {
                        try{
                            ajaxRequest = new ActiveXObject(\"Microsoft.XMLHTTP\");
                        } catch (e){
                            alert(\"Your browser broke!\");
                            return false;
                        }
                    }
                }
                ajaxRequest.onreadystatechange = function(){
                    
                    if(ajaxRequest.readyState == 4){
                        var divc = document.getElementById(div);
                        var result = ajaxRequest.responseText;
                        divc.innerHTML = result;
                        if(!result){
                            ajaxFunction(\"main.php\", \"content\", 1);
                        } else if(result == 'error'){
                            ajaxFunction(\"error.php\", \"content\", 2);
                        }
                        if(menu == 2){
                            var divc = document.getElementById('menu');
                            divc.innerHTML = '';
                        } else if(menu){
                            ajaxFunction(\"menu.php\", \"menu\", 0);
                        }
                    }
                }
                url=encodeURIComponent(url);
                if(!addon){
                    addon = '';
                }
                ajaxRequest.open(\"GET\", \"$cp_content_folder/\" + url + addon, true);
                ajaxRequest.send(null);
            }
            
            function form_submit(url, form){
                var addon = ''
                for(i=0; i < form.elements.length; i++){
                    addon += form.elements[i].name + '=' + form.elements[i].value.replace(/\\n/g,'<br />') + '&';
                }
                ajaxFunction(url, 'content', 0, '?' + addon);
            }
            
            onerror=CallError;
            var txt = \"\";
            function CallError(msg,url,line){
                txt=\"Error: \"+msg+\"\\n\";
                txt=txt+\"URL: \"+url+\"\\n\";
                txt=txt+\"Line: \"+line+\"\\n\\n\";
                alert(txt);
                return true;
            }";
if($cp_nav != ""){
    echo "ajaxFunction('" . $cp_nav . ".php', 'content', 1";
    if($cp_sub != "") echo ", '?sub=" . $cp_sub . "'";
    echo ");";
} else echo "ajaxFunction('logged.php', 'content', 1);";
echo "
            //-->
            </script>";
    
?>
and now to the logged.php, at the top of logged.php i put this:
Code:
<?php
session_start();
if (!isset($_SESSION['user']))
{
 die ("Access Denied");
}
?>
WHEN I CLICK ON THE main page I dont have to type any username or password i just clicked login and it linked me to cp.php and appear only this code :
Code:
stop();     }      //The Ajax function     echo "    ";      ?>
Anyone know what's happening?
Your answer is appreciated.
jera is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-30-2010, 07:57 AM Re: problem connecting login script to sql db
Novice Talker

Posts: 5
Trades: 0
You need the

Quote:
<?php
$username = $_GET['username'];
$password = $_GET['password'];

if(isset($username) && isset($password)) {
$check = mysql_query("SELECT * FROM users WHERE username='$username'");
if(!$check)
echo "Sorry, something wasn't right there";
else
echo "Welcome".$username;
} else {
}
?>
Remember, that won't do anything above, just a preview of what you should do, to check the database for the user/password.
TheNemesis is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to problem connecting login script to sql db
 

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 1.15992 seconds with 12 queries