i trying insert form value database several compulsory field ,but before inserting wanted check if of same value exist in database.for code is
<?php include_once 'header.php';$flag=0; if(isset($_post['submit'])) { $eid =$_post["eid"]; if($eid=="blank") {$flag=1; $iderr="please select e-mitra";} else{ $sqli="select * emitra_device uid='$eid'"; $result1 = $conn->query($sqli); $rowe=mysqli_fetch_array($result1); if($rowe!=""){ $flag=1; $iderr=" user id entered";} } $miatm =trim($_post["miatm"]); if(empty($miatm) || !preg_match("/^[a-za-z0-9 ]*$/",$miatm)) {$flag=1; $mierr="please enter valid id"; } else{$sqlm="select * emitra_device m_sno='$miatm'"; $resultm = $conn->query($sqlm); $rowm=mysqli_fetch_array($resultm); if($rowm!="") {$flag=1;$mierr=" machine id entered";}}
.........and 3 more field
//for insertion
if($flag==0){$sqll="insert *********** "}}?> working
// form coding is...
<form id="basic" method="post" name="basic"> <select class="select-style gender" name="eid"> <option value="blank">please select e-mitra id</option> <option value="****">*****</option></select> <?php echo $iderr;?> <p class="contact"><label for="bid">m/s serial no</label></p> <input type="text" name="miatm" value ="<?php if (isset($miatm)) echo $miatm; ?>"/> <?php echo $mierr; ?> ........more
its working well, know improved . may this
$dupesql = "select * table (uid= '$eid' or ***= '$miatm' or **= '$**')"; $duperaw = mysql_query($dupesql); if (mysql_num_rows($duberaw) > 0) {..... }
but in cannot show user enter duplicate....id/mno/etc. please suggest better way
you can still show user entered duplicate. here way:
you don't need select filed table. select 5 field, on want have duplicate check.
once have result, foreach/for loop check column meets user entered value. whichever meets, that's entered.
$error_array = array(); foreach($duperaw $this_row) { if($this_row['uid'] == $eid) $error_array[] = 'user id entered'; if($this_row['m_sno'] == $miatm) $error_array[] = 'machine id entered'; .. .. .. }
then show full array errors.
Comments
Post a Comment