PHP if if显示错误

时间:2013-09-01 07:48:21

标签: php if-statement

有人可以解释我如何向此添加ele语句,如果字段为空则显示错误吗?

<?php
include_once('config2.php');
?>


<?php
include ('adresa-site.php');
if(isset($_POST['add']))
{
$dbhost = 'localhost';
$dbuser = 'USER';
$dbpass = 'PASS';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Eroare de conexiune: ' . mysql_error());
}

if(! get_magic_quotes_gpc() )
{
$poza = addslashes ($_POST['poza']);
$nume = addslashes ($_POST['nume']);
}
else
{
$poza = htmlentities($_POST['poza'], ENT_QUOTES | ENT_HTML5);
$nume = htmlentities($_POST['nume'], ENT_QUOTES | ENT_HTML5);
}


$sql = "UPDATE users SET poza='$poza'
WHERE nume='$nume'";



mysql_select_db('DATABASE');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Nu s-au putut adauga datele: ' . mysql_error());
}
echo "
AVATAR MODIFICAT CU SUCCES !<br />
DAI REFRESH PAGINII DE PROFIL

";


mysql_close($conn);
}

?>

<form id="curse-form" class="nm" method="post" action="<?php $_PHP_SELF ?>">
<input class="input-large" type="hidden" value="<?php echo $_SESSION['user']['nume'] ?>" name="nume" />
<input class="input-large" type="text" placeholder="LINK AVATAR" name="poza" />
<input class="btn btn-large btn-primary" type="submit" name="add" id="add" value="MODIFICA" />
</form>

如果字段“poza”为空,我想显示错误,我不知道该怎么做。

我是php的新手,所以请理解我..

谢谢!

2 个答案:

答案 0 :(得分:2)

这样的事情对你有用

if(isset($_POST['poza'])){
    //Do something here
} else {
    echo "error";
}

答案 1 :(得分:2)

if(!isset($_POST['poza']) || empty($_POST['poza'])) {
    // poza does not exist or is empty
}

或者strlen($ _ POST ['poza'])=== 0可以工作