PHP MySQL insert file, validating form with IF-statement with OR operator -
i brand new php , not sure if technique practice, code worked until added || (!is_numeric($variable))
portions of if-statements.
i tested code inserting letters number fields ensuring length of string correct. when do, code runs else-statement , echos ".$jname."added.....etc"". mysqli_query
commented out testing. have tried different versions more or less parenthesis.
why won't is_numeric()
catch letters? allowed multiple ! arguments in if-statement?
<?php header('refresh: 3; url=../job_table.php'); require 'connect.php'; $jname = mysqli_real_escape_string($db,$_post['field1']); $jname_length = 25; $jwo = mysqli_real_escape_string($db,$_post['field2']); $jwo_length = 7; $jpo = mysqli_real_escape_string($db,$_post['field3']); $jpo_length = 4; $add_job_query = "insert jobs (name, wo_no, po_no) values ('$jname','$jwo','$jpo')"; if(($jname || $jwo || $jpo ) == "") { echo "<center><h1>please fill fields!</h1></center>"; } elseif(!(strlen($jname) <= $jname_length)) { echo "<center><h1>name must less or equal ".$jname_length." characters!</h1></center>"; } elseif((strlen($jwo) != $jwo_length) || (!is_numeric($jwo))) { echo "<center><h1>wo number must ".$jwo_length." digit number!</h1></center>"; } elseif((strlen($jpo) != $jpo_length) || (!is_numeric($jwo))) { echo "<center><h1>po number must ".$jpo_length." digit number!</h1></center>"; } else { //echo mysqli_query($db,$add_job_query); echo "<center><h1>".$jname." added!</h1><h1>wo number:".$jwo."</h1><h1>po number:".$jpo."</h1></center>"; } echo "<center><h1>please wait.</h1></center>"; ?>
seems me need instead.
if(empty($jname) || empty($jwo) || empty($jpo)){ echo "<center><h1>please fill fields!</h1></center>"; }elseif($jname <= $jname_length){ echo "<center><h1>name must less or equal ".$jname_length." characters!</h1></center>"; }elseif(($jwo != $jwo_length) || (!is_numeric($jwo))){ echo "<center><h1>wo number must ".$jwo_length." digit number!</h1></center>"; }elseif(($jpo != $jpo_length) || (!is_numeric($jwo))){ echo "<center><h1>po number must ".$jpo_length." digit number!</h1></center>"; }else{ //echo mysqli_query($db,$add_job_query); echo "<center><h1>".$jname." added!</h1><h1>wo number:".$jwo."</h1><h1>po number:".$jpo."</h1></center>"; }
Comments
Post a Comment