-2

Can someone explain me how to add an ele statement to this, and show an error if field is empty?

<?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>

I want to show an error if field "poza" it's empty, and i dont know how to do that.

Im newbie in php, so please understand me..

Thank you !

Muzica Veche
  • 65
  • 2
  • 9
  • http://stackoverflow.com/questions/3190464/php-check-if-any-posted-vars-are-empty-form-all-fields-required – Xevelion Sep 01 '13 at 07:54

2 Answers2

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

Alternatively strlen($_POST['poza']) === 0 could work

2

Something like this should work for you

if(isset($_POST['poza'])){
    //Do something here
} else {
    echo "error";
}
Paul Dessert
  • 6,363
  • 8
  • 47
  • 74