如果空帖怎么办?

时间:2014-04-17 18:55:17

标签: php

为什么不做空邮件?

    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");

}

我不知道问题是什么。首先用户输入他的详细信息,这段代码将在mysql中检查和更新。但没有功能。

2 个答案:

答案 0 :(得分:3)

!empty($_POST['...'])更改为empty($_POST['...'])

现在你说:如果fullname 为空,则返回错误“需要使用fullname”。

答案 1 :(得分:1)

你的逻辑是倒退的。通过将!运算符放在empty()之前,您要说"如果此变量不为空"。这与你想要的相反。

变化:

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

为:

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

使用empty()为您的所有支票执行此操作。

Please, don't use mysql_* functions in new code。它们不再被维护and are officially deprecated。请参阅red box?转而了解prepared statements,并使用PDOMySQLi - this article将帮助您确定哪个。如果您选择PDO here is a good tutorial

您也对SQL injections

持开放态度