Tried my best with the title of this question but here goes...
Im setting up a landing page (using dreamweaver) for an app I'm working on and I will be asking potential users to leave their email if they are interested which I will store in a MySQL database.
To do this, on my index.html page I have implemented the following code:
<form action="email.php" method="post" />
<p><input type="text" name="email1" />
<input type="submit" value="Submit" />
</p>
</form>
This creates a simple text entry box for the email and a submit button.
This is of course is linked to the email.php file which contains the following code:
<?php
//I replace these with the correct details
define('DB_NAME', 'Name');
define('DB_USER', 'User');
define('DB_PASSWORD', 'PW');
define('DB_HOST', 'localhost');
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if (!$link) {
die('Could not connect: ' . myself_error());
}
$db_selected = mysql_select_db(DB_NAME, $link);
if (!$db_selected) {
die('Can\'t use ' . DB_NAME . ': ' . mysql_error());
}
echo 'Connected successfully';
$value = $_POST['email1'];
$sql = "INSERT INTO Emails (email) VALUES ('$value')";
if (!mysql_query($sql)) {
die('Error: ' . mysql_error());
}
mysql_close();
?>
When I view my site, the text entry box is there, I can go and enter my details and submit and this sends that info to my MySQL table, Great! However the browser opens the email.php file aka www.domain.com/email.php which displays "Connected successfully" as per my test code above.
Is it possible for me to implement the php code in the background? I do not want visitors who leave their email on my landing page to be redirected to a new page when they click submit instead just a friendly thank you message on the page they are on.
I hope I have explained this well enough and I apologies in advance if this answer has already been cracked on here before.
Thanks!