Can't get my PHP to show error when form field is blank -


i making php journal through form, no matter do, comes posted. i've tried using empty() , null i'm not sure i'm doing wrong.

here html form:

<form action="journal_post.php" method="post">     <p>give entry title.</p>     <input class="input" type="text" name="title" />     <p>what mood today?</p>     <input class="input" type="text" name="mood" />     <p>now please tell me day.</p>     <textarea class="input" name="entry" rows="12" cols="75" type="text"> </textarea>     <br>     <br>     <input class="submit" type="image" src="submit.png" name="submit" value="submit" />  <form> 

here php:

<?php $servername = "localhost"; $username = "root"; $password = "blahblah"; debug_to_console($password); //establishing connection server $connection = mysql_connect($servername, $username, $password);  //selecting database server $journal_db = mysql_select_db("journal_db", $connection); if(isset($_post['submit'])){     //fetching variables of form travels in url     $title = $_post['title'];     $mood = $_post['mood'];     $entry = $_post['entry'];     if($title !=''||$entry !=''){         //insert query of sql         $query = mysql_query("insert entrys(j_title, j_mood, j_entry) values ( '$title', '$mood', '$entry')");          echo "<br/><br/><span>journal entry recorded..!!</span>";     }     else{         echo "<p>insertion failed <br/> fields blank....!!</p>";     } } //closing connection server mysql_close($connection); ?> 

change:

if($title !=''||$entry !=''){ 

to:

if($title !=''&&$entry !=''){ 

you want check both $title and $entry aren't empty, not either-or.


Comments

Popular posts from this blog

matlab - error with cyclic autocorrelation function -

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

c# - What is a good .Net RefEdit control to use with ExcelDna? -