Note that there are some explanatory texts on larger screens.

plurals
  1. POBlank field error check
    primarykey
    data
    text
    <p>I've got a .php registration file that can successfully insert 4 new fields into a user database in my localhost but whenever I add an empty field error check it will stop working. If I don't use an empty field error check all 4 blank values will be added into my user table in localhost. Here's the code in my .php file:</p> <pre><code> &lt;div class="contact"&gt; &lt;div&gt; &lt;h4&gt;Registration Form&lt;/h4&gt; &lt;/div&gt; &lt;div&gt; &lt;table bgcolor="#CCCCCC"&gt; &lt;h4&gt;All fields are necessary and are not to be left empty&lt;/h4&gt; &lt;/br&gt;&lt;/br&gt; &lt;font color="white"&gt;Name&lt;/font&gt;&lt;input class="test1" type="text" id="txNm" value=""&gt; &lt;font color="white"&gt;Username&lt;/font&gt;&lt;input class="test1" type="text" id="txUsn" value=""&gt; &lt;font color="white"&gt;Password&lt;/font&gt;&lt;input class="test1" type="password" id="txPwd" value=""&gt; &lt;font color="white"&gt;E-Mail&lt;/font&gt;&lt;input class="test1" type="text" id="txEml" value=""&gt; &lt;input class="test2" name="Submit" type="submit" value="" id="submit" onClick='submitUser();txNm.value="";txUsn.value="";txPwd.value="";txEml.value="";'/&gt; &lt;/table&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>the submitUser function will then jump over to a js file:</p> <pre><code> function submitUser(){ var name = $('#txNm').val(); var username = $('#txUsn').val(); var password = $('#txPwd').val(); var email = $('#txEml').val(); var finalData = { nm: name, usn: username, pwd: password, eml: email }; $.post('submitUser.php', finalData, function(resp){ if(resp == 'success'){ alert('Thank you for register.'); getUserList(); } }); </code></pre> <p>} then it will jump again go to a submitUser.php file containing the rest of the code here's the contents:</p> <pre><code> $nm = mysql_real_escape_string($_POST["nm"]); $usn = mysql_real_escape_string($_POST["usn"]); $pwd = mysql_real_escape_string($_POST["pwd"]); $eml = mysql_real_escape_string($_POST["eml"]); $q = "INSERT INTO userdb (name, username, password, email) VALUES('$nm','$usn','$pwd','$eml')"; if(!mysql_query($q, $con)){ die('Error: ' . mysql_error()); echo mysql_error(); }else{ echo 'success'; } mysql_close($con); </code></pre> <p>the thing is, everytime I add an empty field error check nothing will happen, if I remove it then the whole registration process will continue but well...even if the fields are all empty.</p> <p>My code is:</p> <pre><code> `if(empty($_POST['txNm'])) { die('You need to enter a value for the Name field'); }` </code></pre> <p>what is wrong with my empty field error check code?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload