Jump to content

database is saving the person information lots of times ??


plodos

Recommended Posts

form.html

<form action="a.php" method="post">
<table border="0" bgcolor="#ececec" cellspacing="5">

<tr>
<td>Name</td><td>
<input name="name" type="text" id="name"  size="25"/></td>
</tr>

<tr>
<td>Surname</td><td>
<input name="surname" type="text" id="surname"   size="25"/></td>
</tr>
</table>
</form>

 

a.php

<?php
include("dbconfig.php");

$name =mysql_real_escape_string($_POST['name']);
$surname = mysql_real_escape_string($_POST['surname']);

$add_person= mysql_query(" INSERT INTO person (fname,lname) VALUES ('$name','$surname')  "); 

if($add_person)
{

include('ok.html');	
}
else
{
echo "Error";
}
?>

 

This is my sample code, I want to improve that, how can I block the repeated data....

 

If the person click the Register button 3 times, database is saving the person information 3 times, and when I listed, query show me 3 same information....

 

what must I do ? I want to see unique information for each person....I want to block multiple records, please help...

So... It would look like this:

 

include("dbconfig.php");

$name =mysql_real_escape_string($_POST['name']);
$surname = mysql_real_escape_string($_POST['surname']);
$sql = mysql_query("SELECT * FROM person WHERE fname = '$name' AND lname = '$surname'");
if(mysql_num_rows($sql) < 1){
$add_person= mysql_query(" INSERT INTO person (fname,lname) VALUES ('$name','$surname')  "); 
if($add_person){
	include('ok.html');	
}
else{
	echo "Error";
}
}

thank you...

 

I used this system

include("dbconfig.php");

$name =mysql_real_escape_string($_POST['name']);
$surname = mysql_real_escape_string($_POST['surname']);
$sql = mysql_query("SELECT * FROM person WHERE fname = '$name' AND lname = '$surname'");
if(mysql_num_rows($sql) < 1){

$add_person= mysql_query(" INSERT INTO person (fname,lname) VALUES ('$name','$surname')  "); 

if($add_person){

include('ok.html');
}
else
echo "Error";
}
}

 

but I have one more question:)

 

phpmyadmin recorded the empty data....If the user click register 5 times...mysql is saving the first data with full information and other 4 fields are empty like

 

 

1 nokia mobile

2               

3               

4               

5

6 samsung mobile

7

8 sony mobile

 

how can I block the emyty data?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.