...

View Full Version : Need a very simple form submission script



dysfunctionGazz
08-29-2009, 03:51 PM
Hi everyone

Could anyone point me in the direction of a REALLY SIMPLE php to mysql form submission script?

Simply, it is for registering an email address and phone number (optional) into my database for membership of a club night.

So i literally want 2 boxes, and they write to 2 columns in a mysql database.

Does anyone have a code snippet or a recommendation of a good tutorial?
I havent done any php for ages and im well out of the loop :(

Gazz

[vengeance]
08-29-2009, 04:05 PM
I wrote something quick for you, which might help you start off with.
It's not perfect, but I think this is what you're looking for.


<?php
if($_POST['formsubmit']){
$email = $_POST['email'];
$phone = $_POST['phone'];

// Error check. You could add more to this.
// For example checking if phone number is supplied, and if it's only integers.
// And if the e-mail address is valid.
if(!$email){
echo "Please supply an e-mail address.";
}else{
$insertData = mysql_query("INSERT INTO `table_name` (`email`,`phone`) VALUES ('".$email."','".$phone."')") or die(mysql_error());
echo "Thank you!";
}
}else{
echo "<form method=\"POST\">";
echo "E-mail: <input type=\"text\" name=\"email\" /><br />";
echo "Phone number: <input type=\"text\" name=\"phone\" /><br />";
echo "<input type=\"submit\" name=\"formsubmit\" value=\"Submit\" />";
echo "</form>";
}
?>

I only added a few lines of comments, feel free to ask, if you need any more help.

dysfunctionGazz
09-13-2009, 05:06 PM
thank you for this, im going to try that out and see how it goes, my web server has expired tho so I gotta get that back online!!!

Zangeel
09-13-2009, 09:58 PM
Of course you'd need a database for that example to work. And you'd want to sanitize that data.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum