Jump to content

Recommended Posts

 

I hve created a registration form and when i submit the form at first the data are not stored on the database and displays Duplicate entry 'suvin_prathab' for key 1 in the browser(suvin_prathab actually the previous entry) . But when i fill the form again and submit it the data are stored .But when i refresh the page again it browser asks for RESEND OR CANCEL when i click RESEND then it shows how can i correct this .I want the data to stored only once .. i need help to sort this thing... I will give the whole code here ...

 

<!--CONNECTING TO THE DATABASE-->

<?php

//ERROR REPORTING AND DISABLING NOTICES

error_reporting(E_ALL & ~E_NOTICE);

 

$connection = mysql_connect("localhost","root","suvin");

if(!$connection){

die("Database Connection Failed !".mysql_error());

}

?>

<!--SELECTING THE DATABASE LOGIN-->

<?php

$db_select = mysql_select_db("guest_book",$connection);

if(!$db_select){

die("Database Selection Failed !".mysql_error());

}

?>

 

 

 

 

 

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Fight Club</title>

</head>

 

<body bgcolor="#A4DA50">

 

<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">

<font face="Arial, Helvetica, sans-serif" size="+1">

<table>

<tr><td width="175">Username:</td><td><input type="text" name="txt_username" /></td></tr><br /><br />

<tr><td width="175">Password:</td><td><input type="password" name="txt_password" /></td></tr><br /><br />

<tr><td width="175">Confrim Password:</td><td><input type="password" name="txt_confirm_pass" /></td></tr><br /><br />

<tr><td width="175">E-Mail:</td><td><input type="text" name="txt_email" /></td></tr><br /><br />

<tr><td width="175">Security Question:</td><td><input type="text" name="txt_security_q" /></td></tr><br /><br />

<tr><td width="175">Answer:</td><td><input type="text" name="txt_answer" /></td></tr><br /><br />

<tr><td width="175"></td><td><input type="submit" name="btn_submit" value="Submit" />

<input type="button" name="btn_cancel" value="Cancel" /></td></tr>

</table>

</font>

</form>

 

<!--WRITING TO THE DATABASE-->

<?php

 

if(isset($_POST['txt_username']) && isset($_POST['txt_password']) && isset($_POST['txt_confirm_pass']) && isset($_POST['txt_email']) && isset($_POST['txt_security_q']) && isset($_POST['txt_answer'])){

$username = $_POST["txt_username"];

$password = $_POST["txt_password"];

$confirm_pass = $_POST["txt_confirm_pass"];

$email = $_POST["txt_email"];

$security_q = $_POST["txt_security_q"];

$answer = $_POST["txt_answer"];

 

$query2 = "INSERT INTO register (username,password,email,security_q,answer,confirm _pass) VALUES ('$username','$password','$email','$security_q','$ answer','$confirm_pass')";

mysql_query($query2,$connection) or die(mysql_error());

}

?>

 

</body>

</html>

<!--CLOSE DATABASE CONNECTION-->

<?php

mysql_close($connection);

?>

Link to comment
https://forums.phpfreaks.com/topic/123130-php-doubt/
Share on other sites

You can use a query and select all users from the databse before insert function and then make na if statment where you will check if you already have this info in db.

 

SELECT * FROM users

if($_PST["username"] == $username && something else && something else ...){
echo "It's already in the db";
} else {
Insert into DB
}

 

Hope, that helps!  ;)

Link to comment
https://forums.phpfreaks.com/topic/123130-php-doubt/#findComment-635918
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.