Jump to content

Im beginer hve a doubt in PHP


suvin_prathab

Recommended Posts

I hve created a registration form and when i submit the form the data are stored in mysql but when i refresh it browser asks for RESEND OR CANCEL when i click RESEND then it shows Duplicate entry 'suvin_prathab' for key 1 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/123128-im-beginer-hve-a-doubt-in-php/
Share on other sites

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.