1

Why don't work $post empty?

    if (isset($_GET['profil_refresh'])){
if( $_SERVER['REQUEST_METHOD'] == 'POST') {
  if (!empty($_POST["fullname"]))
    {echo  "fullname is required";}
// ------------------------
  if (!empty($_POST["email"]))
    {echo  "Email is required";}
// ------------------------
  if (!empty($_POST["fb"]))
    {echo  "varos is required";}
// ------------------------
  if (!empty($_POST["age"]))
    {echo "kor is required";}
// ------------------------
  if (!empty($_POST["aboutme"]))
    {echo "rolad is required";}
}

$loginid = $_SESSION['loginid'];
$hash = $_SESSION['hash'];
$id = $_SESSION['id']; 
$user = $_POST['user'];
$email = $_POST['email'];
$fullname = $_POST['fullname'];
$fb = $_POST['fb'];
$age = $_POST['age'];
$aboutme = $_POST['aboutme'];


mysql_query("UPDATE zl SET email='" .$email. "', fullname='" .$fullname. "', 
fb='" .$fb. "', age='" .$age. "', aboutme='" .$aboutme. "', adatok='OK' WHERE loginid='" .$loginid. "'") 
or die(mysql_error()); 
header("Location: accindex.php");

}

I don't know what is the problem. first the user type his details, and this code will be check and update in mysql. but not function.

Kara
  • 6,115
  • 16
  • 50
  • 57

2 Answers2

3

Change !empty($_POST['...']) to empty($_POST['...']).

Right now you are saying: if fullname is not empty, then return an error "fullname is required".

Sam
  • 20,096
  • 2
  • 45
  • 71
1

Your logic is backwards. By putting the ! operator before empty() you're saying "if this variable is not empty". This is the opposite of what you want.

change:

if (!empty($_POST["fullname"]))

to:

if (empty($_POST["fullname"]))

Do this for all of your checks using empty().

Please, don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.

You are also wide open to SQL injections

Community
  • 1
  • 1
John Conde
  • 217,595
  • 99
  • 455
  • 496