Jump to content

login.submit not working


InsidiousMennace

Recommended Posts

Hey there guys, I think I'm just being a spastic, but I do not know what to do anymore, my javascript does not want to work, before the prepared statements are even ran, where the $_GET['action'] is checked, it already throws out my error that the action can't be run. What am I missing.

 



<?php
require_once 'config.php';

error_reporting(E_ALL);


//Connection to my database
$mysqli = new mysqli(DB_HOST,DB_USER,DB_PASSWORD,DB_DATABASE);

if(mysqli_connect_errno())
            {
                printf("Connection failed: %s\n", mysqli_connect_errno());
                exit();
            }


if($_GET['action'] == 'UserLogin')
    {
            $stmt = $mysqli->stmt_init();
            //prepared statement
            if($stmt = $mysqli->prepare("select * from login where username = ? and password = ?"))
            {
                
                //bind my parameters
                $stmt->bind_param("ss",$username,$password);
                
                $username = $_POST["username"];
                $password = $_POST["password"];
                
                //execute query
                $stmt->execute();
                
                //bind the result variables
                $stmt->bind_result($username,$password);
                
                //Store my values
                $stmt->store_result();
                
                //fetch values
                if($stmt->fetch())
                {
                            $_SESSION["username"] = $username;
                            alert("Authenticated");
                            header("location : Main_menu.php");
                            exit();
                }
                else
                {
                    alert("username or password is incorrect"); 
                }
                
                $stmt->close();
                $stmt->free_result();
                
            }
            else
            {
              echo  "Username or password incorrect"; 
            }
    }
    else
    {
        echo "no";
    }
        $mysqli->close();

?>

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
    </head>
    <script language = "javascript">
        function UserLogin()
        {
            document.login.submit();
        }
    </script>
<form name="login" action="login.php?action=UserLogin" method="post">
    <table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
        <tr>
            <td>
            <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
            <tr>
            <td colspan="3"><strong>Radius Login </strong></td>
        </tr>
        <tr>
            <td width="78">Username</td>
            <td width="6">:</td>
            <td width="294"><input name="username" type="text" id="username"></td>
        </tr>
        <tr>
            <td>Password</td>
            <td>:</td>
            <td><input name="password" type="password" id="password"></td>
        </tr>
        <tr>
            <td> </td>
            <td> </td>
           <td><input type="button" name="Submit" value="Login" onclick="javascript:UserLogin();"/></td>
        </tr>
    </table>
        </td>
        </tr>
    </table>
</form>
</html>

 

 

Link to comment
Share on other sites

  • 2 weeks later...

You certainly are a newbie.  Your html is not setup properly at all.  Try looking at a book and learn the structure of an html page and you'll quickly see why your js is not working.  Also you are missing other important tags.

 

(quick answer - scripts must go in the head section of an html page along with css)

Link to comment
Share on other sites

Using javascript at all in the above example is rather pointless. Just use a normal submit button and remove all the javascript. By using JS to submit your form like that you are doing nothing other than unnecessarily limiting your site to only people who have JS enabled.

Link to comment
Share on other sites

You certainly are a newbie.  Your html is not setup properly at all.  Try looking at a book and learn the structure of an html page and you'll quickly see why your js is not working.  Also you are missing other important tags.

 

(quick answer - scripts must go in the head section of an html page along with css)

 

Sorry, but this is not only wrong, it is often bad practice. Scripts can go anywhere on the page, and often it's best to have them as the last thing on the page for faster page loads. Usually it is best not to include them until they are necessary.

Link to comment
Share on other sites

To the OP - it's always best to explain both exactly what you are trying to do (this does NOT mean how you are trying to do it), an what is happening now that is different to what you want. When you run into errors, you should copy and paste the entire error, as these often help us help you diagnose the issue. Be as descriptive as possible. The surest way to ensure you get a specific answer is to be as clear as possible about what is happening. The more vague the initial post, the less specific our responses will be.

Edited by haku
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.