Email sign up box?

  • goodscams
  • Newbie
  • Newbie
  • No Avatar
  • Joined: Jan 05, 2007
  • Posts: 13
  • Status: Offline

Post January 5th, 2007, 7:46 am

Could someone please show me or point me in the right direction on how to put a simple email sign up box on my website, all i want is name and email address?
Thanks in Advance
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post January 5th, 2007, 7:46 am

  • dyefade
  • Expert
  • Expert
  • User avatar
  • Joined: May 22, 2004
  • Posts: 712
  • Loc: UK
  • Status: Offline

Post January 5th, 2007, 7:56 am

If you just want a point in the right direction (rather than a step-by-step), your best bet would be to use PHP and MySQL. If you've got some cheapo hosting (like we all do :wink:), then 99% chance you've already got all you need.

Make a new MySQL table with fields ID, Name, Email.
Make a form with two input boxes and a submit button, with the form POSTing off to another page (or the same page - up to you!).
Take the POSTed data, and INSERT it into your table.

Reply if you'd like it in more detail, sounds like you're willing to learn though. :)
  • goodscams
  • Newbie
  • Newbie
  • No Avatar
  • Joined: Jan 05, 2007
  • Posts: 13
  • Status: Offline

Post January 5th, 2007, 8:04 am

wow, I'm kind of new to this, I'm in the UK and have a little website which gets about 200 visitors a day and would quite like to get hold of email address so that I can send info every so often. I use Dreamweaver and am very much a novice ;-)

where do i start with a MySQL table?

thanks
  • Tchuki
  • Mastermind
  • Mastermind
  • No Avatar
  • Joined: Sep 30, 2004
  • Posts: 1774
  • Loc: Edinburgh
  • Status: Offline

Post January 5th, 2007, 8:34 am

##--[ SQL ]--##

Code: [ Select ]
CREATE TABLE email_addresses
(
id tinyint(4) AUTO_INCREMENT NOT NULL,
email varchar(80) NOT NULL,
name char(50) NOT NULL,
PRIMARY KEY (id)
);
  1. CREATE TABLE email_addresses
  2. (
  3. id tinyint(4) AUTO_INCREMENT NOT NULL,
  4. email varchar(80) NOT NULL,
  5. name char(50) NOT NULL,
  6. PRIMARY KEY (id)
  7. );



##--[ HTML FORM ]--##

Code: [ Select ]
<html>
<head>
<titleYOURWEBSITE.COM</title>
<body>
<form name="emails" action="process.php" method="post">
<table>
<tr>
<td>Email:</td>
<td><input type="text" name="email" /></td>
</tr>
<tr>
<td>Name:</td>
<td><input type="text" name="name" /></td>
</tr>
</table>
</form>
</body>
</html>
  1. <html>
  2. <head>
  3. <titleYOURWEBSITE.COM</title>
  4. <body>
  5. <form name="emails" action="process.php" method="post">
  6. <table>
  7. <tr>
  8. <td>Email:</td>
  9. <td><input type="text" name="email" /></td>
  10. </tr>
  11. <tr>
  12. <td>Name:</td>
  13. <td><input type="text" name="name" /></td>
  14. </tr>
  15. </table>
  16. </form>
  17. </body>
  18. </html>



##--[ PHP ]--##

PHP Code: [ Select ]
<?PHP
 
 
 
$db_host = 'localhost';
 
$db_user = 'USER';
 
$db_name = 'DB_NAME';
 
$db_pass = 'DB_PASS';
 
 
 
$db = mysql_connect("$db_host", "$db_user", "$db_pass")
 
   or die ("Error connecting to database.");
 
   
 
$connect = mysql_select_db("$db_name", $db)
 
   or die ("Couldn't select the database.");
 
 
 
 
 
$email = $_POST['email'];
 
$name = $_POST['name'];
 
 
 
if(!empty($email) && (!empty($name))) {
 
$query = mysql_query("INSERT INTO email addresses (email, name) VALUES ('$email', '$name')")
 
or die ("Could not insert new data : " . mysql_error());
 
 
 
echo ("THANKS FOR YOUR SUBMISSION !");
 
 
 
?>
  1. <?PHP
  2.  
  3.  
  4.  
  5. $db_host = 'localhost';
  6.  
  7. $db_user = 'USER';
  8.  
  9. $db_name = 'DB_NAME';
  10.  
  11. $db_pass = 'DB_PASS';
  12.  
  13.  
  14.  
  15. $db = mysql_connect("$db_host", "$db_user", "$db_pass")
  16.  
  17.    or die ("Error connecting to database.");
  18.  
  19.    
  20.  
  21. $connect = mysql_select_db("$db_name", $db)
  22.  
  23.    or die ("Couldn't select the database.");
  24.  
  25.  
  26.  
  27.  
  28.  
  29. $email = $_POST['email'];
  30.  
  31. $name = $_POST['name'];
  32.  
  33.  
  34.  
  35. if(!empty($email) && (!empty($name))) {
  36.  
  37. $query = mysql_query("INSERT INTO email addresses (email, name) VALUES ('$email', '$name')")
  38.  
  39. or die ("Could not insert new data : " . mysql_error());
  40.  
  41.  
  42.  
  43. echo ("THANKS FOR YOUR SUBMISSION !");
  44.  
  45.  
  46.  
  47. ?>


That is a very rough example and any info in CAPS should be changed by yourself. The PHP should be saved to a file called process.php and saved in the same directory as your form.
  • goodscams
  • Newbie
  • Newbie
  • No Avatar
  • Joined: Jan 05, 2007
  • Posts: 13
  • Status: Offline

Post January 5th, 2007, 9:09 am

thanks for that
where does the sql code go?
thanks
  • MasterZ
  • Expert
  • Expert
  • User avatar
  • Joined: Dec 04, 2004
  • Posts: 699
  • Loc: Colorado Springs
  • Status: Offline

Post January 5th, 2007, 9:44 am

if you have PHPMyAdmin then you can put it in the code box to create the table, or you can put it in a php script like this

PHP Code: [ Select ]
 
<?php
 
 
 
$create = mysql_query("CREATE TABLE email_addresses (id tinyint(4) AUTO_INCREMENT NOT NULL, email varchar(80) NOT NULL, name char(50) NOT NULL, PRIMARY KEY (id))") or die("Could not create, Error: " .  mysql_error());
 
 
 
?>
 
 
  1.  
  2. <?php
  3.  
  4.  
  5.  
  6. $create = mysql_query("CREATE TABLE email_addresses (id tinyint(4) AUTO_INCREMENT NOT NULL, email varchar(80) NOT NULL, name char(50) NOT NULL, PRIMARY KEY (id))") or die("Could not create, Error: " .  mysql_error());
  7.  
  8.  
  9.  
  10. ?>
  11.  
  12.  


and then just run that script one time, and the table should be there.
Image Eternal Truth Ministry - Biblical Resources, Forums
Have mercy on me, O God, according to your unfailing love; according to your great compassion blot out my transgressions. - Psalm 51:1 http://www.zssites.net - ZS Sites Web Hosting
  • Tchuki
  • Mastermind
  • Mastermind
  • No Avatar
  • Joined: Sep 30, 2004
  • Posts: 1774
  • Loc: Edinburgh
  • Status: Offline

Post January 5th, 2007, 11:33 am

goodscams wrote:
thanks for that
where does the sql code go?
thanks


As stated, if you using PHPMyAdmin you can use the SQL command prompt to create the table from there.

Personaly that is the best and easiest way to do it.
  • goodscams
  • Newbie
  • Newbie
  • No Avatar
  • Joined: Jan 05, 2007
  • Posts: 13
  • Status: Offline

Post January 5th, 2007, 2:37 pm

thanks guys
  • goodscams
  • Newbie
  • Newbie
  • No Avatar
  • Joined: Jan 05, 2007
  • Posts: 13
  • Status: Offline

Post January 5th, 2007, 4:35 pm

I've used the html bit but there is no submit button?
  • Tchuki
  • Mastermind
  • Mastermind
  • No Avatar
  • Joined: Sep 30, 2004
  • Posts: 1774
  • Loc: Edinburgh
  • Status: Offline

Post January 5th, 2007, 5:00 pm

goodscams wrote:
I've used the html bit but there is no submit button?


Lol, woops ...

Code: [ Select ]
<html>
<head>
<titleYOURWEBSITE.COM</title>
<body>
<form name="emails" action="process.php" method="post">
<table>
<tr>
<td>Email:</td>
<td><input type="text" name="email" /></td>
</tr>
<tr>
<td>Name:</td>
<td><input type="text" name="name" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" value="submit" />&nbsp;<input type="reset" value="clear" /></td>
</tr>
</table>
</form>
</body>
</html>
  1. <html>
  2. <head>
  3. <titleYOURWEBSITE.COM</title>
  4. <body>
  5. <form name="emails" action="process.php" method="post">
  6. <table>
  7. <tr>
  8. <td>Email:</td>
  9. <td><input type="text" name="email" /></td>
  10. </tr>
  11. <tr>
  12. <td>Name:</td>
  13. <td><input type="text" name="name" /></td>
  14. </tr>
  15. <tr>
  16. <td>&nbsp;</td>
  17. <td><input type="submit" value="submit" />&nbsp;<input type="reset" value="clear" /></td>
  18. </tr>
  19. </table>
  20. </form>
  21. </body>
  22. </html>
  • goodscams
  • Newbie
  • Newbie
  • No Avatar
  • Joined: Jan 05, 2007
  • Posts: 13
  • Status: Offline

Post January 5th, 2007, 6:03 pm

goodness do you sleep?

Thanks for that

which bits of the php do i have to change

sorry for being a simpleton

I have my SQL table and i have my HTML and have the php but not working
i guess i need to correct something on php?

currently get this message

Parse error: syntax error, unexpected $end in /home2/shareth/public_html/Free/process.php on line 25


Thanks
  • Tchuki
  • Mastermind
  • Mastermind
  • No Avatar
  • Joined: Sep 30, 2004
  • Posts: 1774
  • Loc: Edinburgh
  • Status: Offline

Post January 5th, 2007, 6:13 pm

goodscams wrote:
goodness do you sleep?


Yes, but only when I`m at work ...


Paste the code from your process.php file, as the code I gave did not contain a variable $end.

You will need to amend the following:

username for your DB - name you use to log into PHPMyAdmin
DB name - the name of the DB not that table
DB pass - password you use to log into PHPMyAdmin
  • goodscams
  • Newbie
  • Newbie
  • No Avatar
  • Joined: Jan 05, 2007
  • Posts: 13
  • Status: Offline

Post January 5th, 2007, 6:26 pm

hopefully one last thing my username

is that
1) the username i use to get into my general control panel (when i go from control panel into sql it doesn't ask for user and password)
2) or the username i set up inside SQL
and i guess the same goes for password

I really appreciate your help
thanks
  • Tchuki
  • Mastermind
  • Mastermind
  • No Avatar
  • Joined: Sep 30, 2004
  • Posts: 1774
  • Loc: Edinburgh
  • Status: Offline

Post January 5th, 2007, 6:30 pm

The username and password that you need to place into the PHP code is the username and password you set up "inside SQL" as you put it, otherwise known as phpMyAdmin. :)

No worries, let us know if you get stuck.
  • goodscams
  • Newbie
  • Newbie
  • No Avatar
  • Joined: Jan 05, 2007
  • Posts: 13
  • Status: Offline

Post January 5th, 2007, 6:39 pm

this is my php obviously changed the passwords and usernames to protect the innocent - still getting error

<?PHP

$db_host = 'localhost';
$db_user = 'str';
$db_name = 'str_STR';
$db_pass = 'str';

$db = mysql_connect("$localhost", "$str", "$str")
or die ("Error connecting to database.");

$connect = mysql_select_db("$str", $db)
or die ("Couldn't select the database.");


$email = $_POST['email'];
$name = $_POST['name'];

if(!empty($email) && (!empty($name))) {
$query = mysql_query("INSERT INTO email addresses (email, name) VALUES ('$email', '$name')")
or die ("Could not insert new data : " . mysql_error());

echo ("THANKS FOR YOUR SUBMISSION !");

?>
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post January 5th, 2007, 6:39 pm

Post Information

  • Total Posts in this topic: 28 posts
  • Users browsing this forum: No registered users and 122 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.