[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Have message come after user tries to login

Posted on 2007-11-28
2
Medium Priority
?
200 Views
Last Modified: 2008-02-01
I would like to have my code where nothing happens until the user tries to login.  RIght now, the code runs as the page loads, therefore outputting the error message.  I don't want the error message to be displayed until a user tries to login.

<?php
session_start();
//Pulling info from login page
if ($_SERVER['REQUEST_METHOD']  == "POST") {
     
      $strUsername = $_POST['strUsername'];
      $strPassword = $_POST['strPassword'];
     
}
 
//Connect to the database
$conn = mysql_connect("localhost", "username", "password")
or die(mysql_error());
mysql_select_db("bank");
 
//Select info from the database
$sql_select = mysql_query("select * from login where strUsername = '" . $strUsername . "' and strPassword = '" . md5($strPassword) . "'")
or die(mysql_error());
 
if(mysql_num_rows($sql_select) != 0)
{
        $_SESSION["username"] = $strUsername;
        header("location: index.php");
}
else
{
        $result = "You are not authorized, please register with us.";
}
 
 
session_write_close();
?>
0
Comment
Question by:pingeyeg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 20

Accepted Solution

by:
steelseth12 earned 2000 total points
ID: 20370442
<?php
session_start();
//Pulling info from login page

if(isset($_POST['strUsername'])) { // check if form has been submitted

      if ($_SERVER['REQUEST_METHOD']  == "POST") {
             
              $strUsername = $_POST['strUsername'];
              $strPassword = $_POST['strPassword'];
             
      }
      
      //Connect to the database
      $conn = mysql_connect("localhost", "username", "password")
      or die(mysql_error());
      mysql_select_db("bank");
      
      //Select info from the database
      $sql_select = mysql_query("select * from login where strUsername = '" . $strUsername . "' and strPassword = '" . md5($strPassword) . "'")
      or die(mysql_error());
      
      if(mysql_num_rows($sql_select) != 0)
      {
                  $_SESSION["username"] = $strUsername;
                  header("location: index.php");
      }
      else
      {
                  $result = "You are not authorized, please register with us.";
      }

}
 
 
session_write_close();
?>
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 20370459
Awesome!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question