Email sign up box?

  • goodscams
  • Newbie
  • Newbie
  • goodscams
  • Posts: 13

Post 3+ Months Ago

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
  • dyefade
  • Expert
  • Expert
  • User avatar
  • Posts: 712
  • Loc: UK

Post 3+ Months Ago

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
  • goodscams
  • Posts: 13

Post 3+ Months Ago

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
  • Tchuki
  • Posts: 1774
  • Loc: Edinburgh

Post 3+ Months Ago

##--[ 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
  • goodscams
  • Posts: 13

Post 3+ Months Ago

thanks for that
where does the sql code go?
thanks
  • MasterZ
  • Expert
  • Expert
  • User avatar
  • Posts: 699
  • Loc: Colorado Springs

Post 3+ Months Ago

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.
  • Tchuki
  • Mastermind
  • Mastermind
  • Tchuki
  • Posts: 1774
  • Loc: Edinburgh

Post 3+ Months Ago

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
  • goodscams
  • Posts: 13

Post 3+ Months Ago

thanks guys
  • goodscams
  • Newbie
  • Newbie
  • goodscams
  • Posts: 13

Post 3+ Months Ago

I've used the html bit but there is no submit button?
  • Tchuki
  • Mastermind
  • Mastermind
  • Tchuki
  • Posts: 1774
  • Loc: Edinburgh

Post 3+ Months Ago

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
  • goodscams
  • Posts: 13

Post 3+ Months Ago

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
  • Tchuki
  • Posts: 1774
  • Loc: Edinburgh

Post 3+ Months Ago

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
  • goodscams
  • Posts: 13

Post 3+ Months Ago

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
  • Tchuki
  • Posts: 1774
  • Loc: Edinburgh

Post 3+ Months Ago

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
  • goodscams
  • Posts: 13

Post 3+ Months Ago

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 !");

?>
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13504
  • Loc: Florida

Post 3+ Months Ago

Is that "Goods Cams" or "Good Scams" ?
  • Tchuki
  • Mastermind
  • Mastermind
  • Tchuki
  • Posts: 1774
  • Loc: Edinburgh

Post 3+ Months Ago

##--[ FIND ]--##
PHP Code: [ Select ]
$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.");
  1. $db = mysql_connect("$localhost", "$str", "$str")
  2.  
  3.  
  4.  
  5. or die ("Error connecting to database.");
  6.  
  7.  
  8.  
  9. $connect = mysql_select_db("$str", $db)
  10.  
  11.  
  12.  
  13. or die ("Couldn't select the database.");



##--[ REPLACE WITH ]--##
PHP Code: [ Select ]
$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.");
  1. $db  =  mysql_connect("$db_host",  "$db_user",  "$db_pass")
  2.  
  3.         or  die  ("Error  connecting  to  database.");
  4.  
  5.        
  6.  
  7. $connect  =  mysql_select_db("$db_name",  $db)
  8.  
  9.         or  die  ("Couldn't  select  the  database.");


You dont need to edit the REPLACE WITH code, the first four variables of the PHP code are "pointers" for that code.
  • Tchuki
  • Mastermind
  • Mastermind
  • Tchuki
  • Posts: 1774
  • Loc: Edinburgh

Post 3+ Months Ago

joebert wrote:
Is that "Goods Cams" or "Good Scams" ?


Must admit, that has crossed my mind aswell :wink:
  • goodscams
  • Newbie
  • Newbie
  • goodscams
  • Posts: 13

Post 3+ Months Ago

changed the { five lines up for ;

now get

Could not insert new data : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'addresses (email, name) VALUES ('aca@hotmail.com', 'g')' at line 1

Thanks for your help

Its Good scams, I like to abuse the supermarkets when i can with scams, legitimate I may add

cheers
  • Tchuki
  • Mastermind
  • Mastermind
  • Tchuki
  • Posts: 1774
  • Loc: Edinburgh

Post 3+ Months Ago

Hmm, Syntax error:


##--[ FIND ]--##

PHP Code: [ Select ]
 
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.  
  2. if(!empty($email) && (!empty($name))) {
  3.  
  4. $query = mysql_query("INSERT INTO email addresses (email, name) VALUES ('$email', '$name')")
  5.  
  6. or die ("Could not insert new data : " . mysql_error());
  7.  
  8.  
  9.  
  10. echo ("THANKS FOR YOUR SUBMISSION !");



##--[ REPLACE WITH ]--##

PHP Code: [ Select ]
 
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.  
  2. if(!empty($email) && (!empty($name))) {
  3.  
  4.  
  5.  
  6. $query = mysql_query("INSERT INTO email addresses (email, name) VALUES ('$email', '$name')")
  7.  
  8. or die ("Could not insert new data : " . mysql_error());
  9.  
  10.  
  11.  
  12. echo ("THANKS FOR YOUR SUBMISSION !");
  13.  
  14.  
  15.  
  16. }
  • goodscams
  • Newbie
  • Newbie
  • goodscams
  • Posts: 13

Post 3+ Months Ago

getting there it just says

Could not insert new data : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'addresses (email, name) VALUES ('aca@hotmail.com', 'G')' at line 1


Is it maybe the code i used in SQL rather than PHP bit?

Thanks in advance
  • Tchuki
  • Mastermind
  • Mastermind
  • Tchuki
  • Posts: 1774
  • Loc: Edinburgh

Post 3+ Months Ago

Nah mate, its me being a muppet and not checking my syntax before making a post.


##--[ FIND IN LINE ]--##
PHP Code: [ Select ]
email addresses


##--[ REPLACE IN LINE WITH ]--##
PHP Code: [ Select ]
email_addresses



^^ or what ever you have named your DB, but make sure it has no spaces in it, spaces should be replaced by an underscore character.
  • goodscams
  • Newbie
  • Newbie
  • goodscams
  • Posts: 13

Post 3+ Months Ago

Can't quite see where you mean this is what I have now, Thanks

<?PHP

$db_host = 'localhost';
$db_user = 'th';
$db_name = 'STR';
$db_pass = 'a7';

$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 !");

}

?>
  • Tchuki
  • Mastermind
  • Mastermind
  • Tchuki
  • Posts: 1774
  • Loc: Edinburgh

Post 3+ Months Ago

Replace your code with the following:

PHP Code: [ Select ]
<?PHP
 
 
 
$db_host = 'localhost';
 
 
 
$db_user = 'th';
 
 
 
$db_name = 'STR';
 
 
 
$db_pass = 'a7';
 
 
 
$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.  
  8.  
  9. $db_user = 'th';
  10.  
  11.  
  12.  
  13. $db_name = 'STR';
  14.  
  15.  
  16.  
  17. $db_pass = 'a7';
  18.  
  19.  
  20.  
  21. $db = mysql_connect("$db_host", "$db_user", "$db_pass")
  22.  
  23.  
  24.  
  25. or die ("Error connecting to database.");
  26.  
  27.  
  28.  
  29. $connect = mysql_select_db("$db_name", $db)
  30.  
  31.  
  32.  
  33. or die ("Couldn't select the database.");
  34.  
  35.  
  36.  
  37. $email = $_POST['email'];
  38.  
  39.  
  40.  
  41. $name = $_POST['name'];
  42.  
  43.  
  44.  
  45. if(!empty($email) && (!empty($name))) {
  46.  
  47.  
  48.  
  49. $query = mysql_query("INSERT INTO email_addresses (email, name) VALUES ('$email', '$name')")
  50.  
  51.  
  52.  
  53. or die ("Could not insert new data : " . mysql_error());
  54.  
  55.  
  56.  
  57. echo ("THANKS FOR YOUR SUBMISSION !");
  58.  
  59.  
  60.  
  61. }
  62.  
  63.  
  64.  
  65. ?>


Note the line:

PHP Code: [ Select ]
$query = mysql_query("INSERT INTO email_addresses (email, name) VALUES ('$email', '$name')")
and that the table name now contains an underscore instead of white space. You will need to change your table name accoringly in your DB as well.
  • goodscams
  • Newbie
  • Newbie
  • goodscams
  • Posts: 13

Post 3+ Months Ago

WOW it works, thank you very very much

how do i get the HTML table to be small table as part of an existing web page rather than one page in itself?

Thanks
  • Tchuki
  • Mastermind
  • Mastermind
  • Tchuki
  • Posts: 1774
  • Loc: Edinburgh

Post 3+ Months Ago

Paste:

Code: [ Select ]
<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>
  1. <form name="emails" action="process.php" method="post">
  2. <table>
  3. <tr>
  4. <td>Email:</td>
  5. <td><input type="text" name="email" /></td>
  6. </tr>
  7. <tr>
  8. <td>Name:</td>
  9. <td><input type="text" name="name" /></td>
  10. </tr>
  11. </table>
  12. </form>


Where ever you want the email form to appear on your page, so just add it to your HTML page somewhere.

Sorry it took so long to get it to work, if I had checked my syntax the first time [ which I should have ] it would have been working a lot quicker,
  • goodscams
  • Newbie
  • Newbie
  • goodscams
  • Posts: 13

Post 3+ Months Ago

Thanks Tchuki for all your help
  • TonyMatt1
  • Born
  • Born
  • TonyMatt1
  • Posts: 1

Post 3+ Months Ago

Hi,

Reviving an oldie I guess...

I came across this thread which is very helpful. This helped me start to learn php, so it's a little at a time.

This code works for me but I do have a couple questions if someone here may be able to help.

If an email is not submitted or it is not proper, and someone clicks the submit button, the thank you page still shows up, it is blank (without the thank you). I am trying to figure out how to get that page to state there is an error and to please try again.

If anyone can offer some help, it would be appreciated.

Thank you,
Tony M

Post Information

  • Total Posts in this topic: 28 posts
  • Users browsing this forum: No registered users and 135 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
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.