Member Avatar for sundeep.gurroby

Trying to create a registration page...but i notice that Data is being sent to database on page load. I would like this to happen when the user click on Register button. What am i doing wrong...any solotion please?
My database is below and code is also below:

<?php require_once('Connections/bankusers.php'); ?>

<?php

// table name
$tbl_name=temp_users_db;

// Random confirmation code
$confirm_code=md5(uniqid(rand()));

// values sent from form
$Address=$_POST['Address'];
$FirstName=$_POST['FirstName'];
$LastName=$_POST['LastName'];
$Email=$_POST['Email'];
$UserName=$_POST['UserName'];


// Insert data into database
$sql="INSERT INTO $tbl_name(confirm_code,Address, FirstName,LastName,Email,UserName,Password)VALUES('$confirm_code','$Address','$FirstName','$LastName','$Email', '$UserName', '$Password')";
mysql_select_db($database_bankusers, $bankusers);
$result=mysql_query($sql);

// if suceesfully inserted data into database, send confirmation link to email
if($result){

// ---------------- SEND MAIL FORM ----------------


// send e-mail to ...
$to=$Email;

// Your subject
$subject="Your confirmation link here";

// From
$header="from: Administrator <admin@modelonlinebank.com>";

// Your message
$message="Your Comfirmation link \r\n";
$message.="Click on this link to activate your account \r\n";
$message.="http://www.modelonlinebank.com/confirmation.php?passkey=$confirm_code";


// send email
$sentmail = mail($to,$subject,$message,$header);

}


// if not found
else {
echo "Not found your email in our database";
}


// if your email succesfully sent
if($sentmail){
echo "Your Confirmation link Has Been Sent To Your Email Address.";
}
else {
echo "Cannot send Confirmation link to your e-mail address";
}




?>

This page is the same page that show the HTML? If so, all this code is being executed before any user interaction...

I suggest that you create an hidden input to know what do to... example:

<?php
    if ( $_POST["formAction"] == "insert" ) {
        // Insert code goes here
    }
?>

<input type="hidden" name="formAction" value="none"/>

<button type="submit" onclick="document.form.formAction.value = 'insert'; return true;">Send</button>
Member Avatar for sundeep.gurroby

Thanks mate! I have found the solution by putting the form and the php process in two different pages and its working as expected...with little issue in database.I will consider it solved. And looking to deal with my next issue.

Member Avatar for sundeep.gurroby

solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.