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...

Link to comment
Share on other sites

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";
}
}

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.