zirgs Posted June 21, 2006 Share Posted June 21, 2006 hi there i'm using this code[code]<?phpif ( $_POST['author']=="name" || $_POST['comment']=="comment" ){if (isset($_POST)){echo "Some fields were left blank!";}}elseif ( $_POST['author']=="" || $_POST['comment']=="" ){if (!isset($_POST)){echo "Some fields were left blank!";}}else{include 'db_connect.php';$date = date('d/m/Y G:i');$query="INSERT INTO comments (newid,author,comment,date) VALUES ('$_POST[id]','$_POST[author]','$_POST[comment]','$date')";if(mysql_db_query($current_db,$query)){echo "Comment added!";mysql_close($database);}}?>[/code]it works fine until i press submit when there isn't anything writen into fields.I need to then show "Some fields were left blank!"anyone help ? what i'm doing wrong?thanks. Quote Link to comment https://forums.phpfreaks.com/topic/12589-check-if-empty/ Share on other sites More sharing options...
michaellunsford Posted June 21, 2006 Share Posted June 21, 2006 a few things. your first set says "isset($_POST)" and the second says "!isset($_POST)" That might be a problem.Another area I'd do differently is the $_POST['whatever']=="". Maybe a strlen($_POST['whatever'])>0 or !$_POST['whatever'].I'd also reduce the if statements a bit by putting the if($_POST) up top, instead of checking for post under each if statement.So, if I may rewrite a bit:[code]<?phpif($_POST) { if ( $_POST['author']=="name" || $_POST['comment']=="comment" ) { echo "Some fields were left blank!"; } elseif ( !$_POST['author'] || !$_POST['comment'] ) { echo "Some fields were left blank!"; } else { include 'db_connect.php'; $date = date('d/m/Y G:i'); $query="INSERT INTO comments (newid,author,comment,date) VALUES ('$_POST[id]','$_POST[author]','$_POST[comment]','$date')"; if(mysql_db_query($current_db,$query)) { echo "Comment added!"; mysql_close($database); }}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/12589-check-if-empty/#findComment-48246 Share on other sites More sharing options...
zirgs Posted June 21, 2006 Author Share Posted June 21, 2006 ok i'll try it out later.thanks. Quote Link to comment https://forums.phpfreaks.com/topic/12589-check-if-empty/#findComment-48252 Share on other sites More sharing options...
zirgs Posted June 22, 2006 Author Share Posted June 22, 2006 ok it didn't work for me what i wanted .... ok anyone knows how to check if form was submited or not (i mean if submit button was pressed) ... any help? Quote Link to comment https://forums.phpfreaks.com/topic/12589-check-if-empty/#findComment-48388 Share on other sites More sharing options...
.josh Posted June 22, 2006 Share Posted June 22, 2006 to check to see if the user pressed the submit button, you would name your submit button. example:<input type = 'submit' name='submit' value='submit'>and then in your processing script, you would do like so:if($_POST['submit']) {...}but overall, check out this thread:[a href=\"http://www.phpfreaks.com/forums/index.php?showtopic=96378&hl=\" target=\"_blank\"]http://www.phpfreaks.com/forums/index.php?...topic=96378&hl=[/a] Quote Link to comment https://forums.phpfreaks.com/topic/12589-check-if-empty/#findComment-48395 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.