Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10

Thread: Help!

  1. #1
    New Coder
    Join Date
    Jul 2010
    Posts
    66
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Help!

    Hey guys,

    Im new at this and am trying to create a email subscribe thing. So people enter the email and click submit, the emails then need to go to a database.

    I do not know how to do this, any ideas?

    Joe

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    While you're checking out Aero's links, also see this one. Specifically #2.
    Are you a Help Vampire?

  • #4
    New Coder
    Join Date
    Jul 2010
    Posts
    66
    Thanks
    11
    Thanked 0 Times in 0 Posts
    I have got this far:
    This is my HTML document:
    Code:
    <html>
    <head>
    	<title>Join Mailing List</title>
    <!-- define some style elements-->
    <style>
    h1
    {
    	font-family : Arial, Helvetica, sans-serif;
    	font-size : 16px;
        font-weight : bold;
    }
    label,a 
    {
    	font-family : Arial, Helvetica, sans-serif;
    	font-size : 12px; 
    }
    
    </style>	
    <!-- a helper script for vaidating the form-->
    <script language="JavaScript" src="scripts/gen_validatorv31.js" type="text/javascript"></script>
    </head>	
    </head>
    
    <body>
    <h1>Contact us</h1>
    <form method="POST" name="contactform" action="contact-form-handler.php"> 
    <p>
    <label for='name'>Your Name:</label> <br>
    <input type="text" name="name">
    </p>
    <p>
    <label for='email'>Email Address:</label> <br>
    <input type="text" name="email"> <br>
    </p>
    <input type="submit" value="Submit"><br>
    </form>
    
    <script language="JavaScript">
    // Code for validating the form
    // Visit http://www.javascript-coder.com/html...lidation.phtml
    // for details
    var frmvalidator  = new Validator("contactform");
    frmvalidator.addValidation("name","req","Please provide your name"); 
    frmvalidator.addValidation("email","req","Please provide your email"); 
    frmvalidator.addValidation("email","email","Please enter a valid email address"); 
    </script>
    </body>
    </html>
    And this is my .PHP.....

    Code:
    <?php 
    $errors = '';
    $myemail = 'joesruddock@hotmail.com';//<-----Put Your email address here.
    if(empty($_POST['name'])  || 
       empty($_POST['email']) || 
       empty($_POST['message']))
    {
        $errors .= "\n Error: all fields are required";
    }
    
    $name = $_POST['name']; 
    $email_address = $_POST['email']; 
    $message = $_POST['message']; 
    
    if (!eregi(
    "^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", 
    $email_address))
    {
        $errors .= "\n Error: Invalid email address";
    }
    
    if( empty($errors))
    {
    	$to = $myemail; 
    	$email_subject = "Contact form submission: $name";
    	$email_body = "You have received a new message. ".
    	" Here are the details:\n Name: $name \n Email: $email_address \n Message \n $message"; 
    	
    	$headers = "From: $myemail"; 
    	$headers .= "Reply-To: $email_address";
    	
    	mail($to,$email_subject,$email_body,$headers);
    	//redirect to the 'thank you' page
    	header('Location: contact-form-thank-you.html');
    } 
    ?>
    <html>
    <head>
    	<title>Contact form handler</title>
    </head>
    
    <body>
    <!-- This page is displayed only if there is some error -->
    <?php
    echo nl2br($errors);
    ?>
    
    
    </body>
    </html>

    It just opens a download window for the .PHP file rather than saving the info in it and redirecting to the tank you page...
    Last edited by joesruddock; 07-29-2010 at 03:43 PM.

  • #5
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    Quote Originally Posted by joesruddock View Post
    It just opens a download window for the .PHP file rather than saving the info in it and redirecting to the tank you page...
    That sounds like PHP isn't working on the server. Does your hosting account include PHP?
    Are you a Help Vampire?

  • #6
    New Coder
    Join Date
    Jul 2010
    Posts
    66
    Thanks
    11
    Thanked 0 Times in 0 Posts
    Just running it locally atm...

  • #7
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    It's going to be like pulling teeth to get information, isn't it?

    Are you running on WAMP? LAMP? Just slopping stuff into Notepad and expecting it to work?
    Are you a Help Vampire?

  • #8
    New Coder
    Join Date
    Jul 2010
    Posts
    66
    Thanks
    11
    Thanked 0 Times in 0 Posts
    Sorry, I dont know much about this kinda stuff...

    Ive been using dreamweaver Cs5...

  • #9
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    I don't know how Dreamweaver works. PHP, though, requires a PHP server to be operating. DW may handle that itself while developing inside it, but if you're testing the site through the browser, as it sounds, the PHP is just some unknown file type so it triggers a download.

    If you're going to test PHP locally, you need a server set up. Check out WAMP.
    Are you a Help Vampire?

  • #10
    Regular Coder djh101's Avatar
    Join Date
    May 2009
    Location
    California
    Posts
    616
    Thanks
    48
    Thanked 65 Times in 65 Posts
    I wouldn't recommend setting up your own server, it can pretty complicated and not necessary for such a small and simple site. Most web hosts (if not all) support PHP depending on your plan and provide you with mysql databases. As above poster said, tizag.com has some great tutorials, that's where a learned PHP and mySQL (that and occasional questions on here). Anyway, once you get your database set up, the code is very simple:
    PHP Code:
    $hostname 'database.db.4944466.hostedresource.com';
    $dbname 'database';
    $username 'database';
    $password 'password';
        
    $connect mysql_connect($hostname$username$password) or die(mysql_error());
        
    mysql_select_db($dbname) or die(mysql_error());

    $name $_POST['name'];
    $email $_POST['email'];
    $query "INSERT INTO maillist (name,email) VALUES('$name', '$email')";
            
    mysql_query($query) or die(mysql_error()); 
    What the above does is first connect to your database. Next, I am going to assume you submitted a form with the post method to this page. We retrieved data from 'name' and 'email' and turned them into PHP variables. After that we made a variable that is going to become our mySQL query and made it a mySQL statement that inserts $name and $email into rows 'name' and email' in a table called 'maillist'. The last line (mysql_query($query)) runs a mysql query with your query variable used as the actual query part.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •