PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, May 16, 2022

[FIXED] How to check whether a post was made or not?

 May 16, 2022     easyphp, php, post, xdebug     No comments   

Issue

if(isset($_POST["email"]))
{
$email = mysql_real_escape_string($_POST["email"]); /* Line 10 */
$password = mysql_real_escape_string($_POST["password"]);

$result = mysql_query("SELECT password, id FROM users WHERE email = '$email'");

if (!$result)
    {
        die('Invalid query: ' . mysql_error());
    }

$row = mysql_fetch_assoc($result);

if($row['password'] == $password)
    {
        ini_set("session.cookie_lifetime","360000");
        session_start();
        $_SESSION['valid_user'] = $row['id'];
        $_SESSION['email'] = $row['email'];
        mysql_close($link);
        header('Location: index.php');
    }


mysql_close($link);
}

I'm not making any posts but it says that $email is not defined at line 10. Why? I use EasyPHP.

Notice: Undefined index: email in C:\Program Files\EasyPHP-5.3.5.0\www\v0.3\model\login.php on line 10


Solution

The most reliable method for checking if a POST was done is via

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
   ... you're in a post ...
}

Checking for a particular form field is risky - you might rename/delete the field and forget to update the form. But checking for that $_SERVER value is 100% reliable - it's always available, regardless of what method the script was invoked via.



Answered By - Marc B
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing