martynball
New Member
- Messages
- 60
- Reaction score
- 0
- Points
- 0
At the moment I use this;
<form name="form1" method="post" action="scripts/update.php">
I want to add the php script under my form code so that the echo function will write the text in the current document, because my current action loads a new page (update.php).
I have added a function to the script and included into the document under the form, now what do I type into the action="" to call the function?
update.php
<form name="form1" method="post" action="scripts/update.php">
I want to add the php script under my form code so that the echo function will write the text in the current document, because my current action loads a new page (update.php).
I have added a function to the script and included into the document under the form, now what do I type into the action="" to call the function?
PHP:
<form name="form1" method="post" action="scripts/update.php">
<p class="g2">Name:</p>
<input type="text" class="contact-feild" name="name" size="20" />
<br />
<p class="g2">Email:</p>
<input type="text" class="contact-feild" name="email" size="20" />
<br />
<p class="g2">Message:</p>
<textarea name="message" class="contact-feild" style="width:300px; height:150px; overflow:scroll; overflow-x:hidden;">
</textarea>
<br />
<input type="submit" value="Submit" class="button" name="submit"/>
</form>
<?php include 'scripts/update.php'; ?>
update.php
PHP:
<?php
function sendData()
{
// Connect to database
$con = mysql_connect("localhost","martynba_martynb","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
// Select table
mysql_select_db("martynba_comments", $con);
// Make varibles
date_default_timezone_set('GMT');
$name = mysql_real_escape_string($_POST['name']);
$email = mysql_real_escape_string($_POST['email']);
$message = mysql_real_escape_string($_POST['message']);
$date = date("F j, Y, g:i a");
// Check data has been inputted
if (empty($name)) {
echo 'Please enter your name! <br />';
}
// Insert data
$query="INSERT INTO commentTable ( NAME, EMAIL, MESSAGE, DATE)
VALUES ('".$name."','".$email."','".$message."','".$date."')";
$result = mysql_query ($query);
header('Location: http://martynleeball.x10hosting.com/thanks.php');
}
?>
Last edited: