How to Prevent Redundancy or Duplication of Entries



SAMPLE




HTML CODES
<html>
<head>
      <title></title>
      <link rel="stylesheet" type="text/css" href="cute.css">

</head>

<body background="ANIME.jpg" width="100px">
<center>
<form action="joanl.php" method='POST'>
<div id="joan">
<h1> Sign up! </h1>
<tr>
<td><b>Firstname:</b> </td><br>
<input type="text" name="fn"><br>
</tr>
<tr>
<td><b>Middlename:</b> </td><br>
<input type="text" name="mn"><br>
</tr>
<tr>
<td><b>Lastname: </b></td><br>
<input type="text" name="ln"><br>
</tr>
<tr>
<td></td><br><br>
<input type="submit" value="SUBMIT"><br>
</tr>
</div>
</center>
</form>
</body>
</html>

CSS CODES

#joan{
     
     
background:powderblue;
      height: 600px;
      width: 350px;
      background-image: url("gwapa.jpg");
      text-align:center;
      color:black;
      letter-spacing: 3px;
      font-family:courier;
      line-height: 5em;
      border-radius:15px 50px;
      padding: 20px;
      width: 350x;
      height: 600px;


}


PHP CODES

<?php


mysql_connect("localhost","root","");
mysql_select_db("db_connect");


$fn = $_POST['fn'];
$mn = $_POST['mn'];
$ln = $_POST['ln'];

$error=array();
$errorw=false;

if($fn==' '){
$error[]= 'Firstname is missing';
$errorw=true;
}

if($mn==''){
$error[]= 'Middlename is missing';
$errorw=true;
}

if($ln== ''){
$error[]= ' Lastname is missing';
$errorw=true;
}

if($fn !=' '){
$qry = "SELECT * FROM tbl_connect WHERE Firstname = '$fn'";
$result = mysql_query($qry);
if($result){
if(mysql_num_rows($result) > 0 ) {
$error[]= '';
$errorw = true;    
}

@mysql_free_result($result);
}
else {
die("Query failed");
}
}
if($errorw){
$_SESSION['ERROR'] = $error;
session_write_close();
header("location: joanllamedo.php");
exit();

}
mysql_query("INSERT INTO tbl_connect values('$fn','$mn','$ln');");
echo "INSERTED";

?>



Inputting Data




Submitting the Data



Now let’s check it if it’s inserted to DATABASE .
Let’s use CMD .




Yes, it is already inserted .

Now , let’s check if we can entry the same value ‘ Joan Buck LLamedo ‘
Let’s go back to the Form.




No, we can’t enter the same entry.




Since we are using this codes ..
$error=array();
$errorw=false;

if($fn==' '){
$error[]= 'Firstname is missing';
$errorw=true;
}

if($mn==''){
$error[]= 'Middlename is missing';
$errorw=true;
}

if($ln== ''){
$error[]= ' Lastname is missing';
$errorw=true;
}

if($fn !=' '){
$qry = "SELECT * FROM tbl_connect WHERE Firstname = '$fn'";
$result = mysql_query($qry);
if($result){
if(mysql_num_rows($result) > 0 ) {
$error[]= '';
$errorw = true;  
}

@mysql_free_result($result);
}
else {
die("Query failed");
}
}
if($errorw){
$_SESSION['ERROR'] = $error;
session_write_close();
header("location: joanllamedo.php");
exit();

}




THANKS!



Comments

Popular Posts