Note that there are some explanatory texts on larger screens.

plurals
  1. POData cannot insert to database when no more error is detect
    primarykey
    data
    text
    <blockquote> <p><strong>Here is my code</strong></p> <blockquote> <p><em><strong>Whether is my if-else statement got problem or insert there got any problem</em></strong></p> </blockquote> </blockquote> <p>if(isset($_POST["Add"])) {</p> <pre><code> $name = $_POST["username"]; $pass = $_POST["password"]; $fname = $_POST["fname"]; $lname = $_POST["lname"]; $hph = $_POST["home"]; $hp = $_POST["hp"]; $mail = $_POST["email"]; $add = $_POST["address"]; $age = $_POST["age"]; $pos = $_POST["position"]; $dept = $_POST["dept"]; </code></pre> <p>$result <strong>i use it to check out my username</strong></p> <pre><code> $result=mysql_query("select*from employee where Emp_Username='$name'"); if($name==""||$pass==""||$fname==""||$lname==""||$hph==""||$hp==""||$mail==""||$add==""||$age==""||$pos==""||$dept=="") { ?&gt; &lt;script type="text/javascript"&gt; alert("Please fill in all the required informations."); &lt;/script&gt; &lt;?php } elseif(empty($errors)===true) { if (!preg_match("/^[A-Z][a-zA-Z -]+$/i",$_POST['fname'])) { $fnameErr= 'Invalid key has been input*'; } if (!preg_match("/^[A-Z][a-zA-Z -]+$/i",$_POST['lname']) ) { $lnameErr= 'Invalid key has been input*'; } if (filter_var($mail, FILTER_VALIDATE_EMAIL) === false) { $mailErr = 'A valid email address is required*'; } if (!preg_match('/^[0-9]{1,}/', $_POST['age'])) { $ageErr = 'Only can be numeric*'; } if (!preg_match("/^[a-zA-Z0-9 _.,:\"\']+$/i", $_POST['address'])) { $addErr = 'Address must be letters and numbers*'; } if (!preg_match("/^[0-9]{2,2}[-][0-9]{7,7}$/", $_POST['home'])) { $hphErr= 'Phone must comply with this mask: 04-4XX1234*'; } if (!preg_match("/^[0-9]{3,3}[-][0-9]{7,7}$/", $_POST['hp'])) { $hpErr= 'Phone must comply with this mask: 014-XXX1234*'; } if(strlen($name)&lt;4) { $nameErr = 'Your username must between 4 to 12 characters*'; } if (strlen($pass) &lt; 6) { $passErr = 'Your password must be at least 6 characters*'; } } elseif(mysql_num_rows($result)==0) </code></pre> <p>if $result==0 so my data will insert to the employee table, but it can't work</p> <pre><code> { mysql_query("insert into employee(Dept_ID, Emp_Address, Emp_Age, Position, Emp_Username, Emp_Password, Emp_Fname, Emp_Lname, ContactNo_Home, ContactNo_HP, Emp_Email) values('$dept','$add','$age','$pos','$name','$pass','$fname','$lname','$hph','$hp','$mail')"); ?&gt; &lt;script type="text/javascript"&gt; alert('Registered successfully!'); &lt;/script&gt; &lt;?php } else { ?&gt; &lt;script type="text/javascript"&gt; alert("Username already in use!"); &lt;/script&gt; &lt;?php } } </code></pre> <p>Hopefully someone can help me find out the problem and solve it. Thank you! </p>
    singulars
    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.
 

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