How to do this

Discussion in 'PHP' started by aladinhw, Aug 1, 2009.

  1. #1
    hello
    I have a HTML page and I want to add this to it ( like explained in the picture ) . I can do HTML but I don't know a lot about PHP and how to connect it with MySQL. I need to put the code on my HTML page and when people press the add botton , the script test the boxes and see if the " E-mail " is real and if the other boxes are filled or not then IF everything is good , It sends the " Email " boxe , the " Number " boxe , and the " comment '' boxe to my SQL database. All what I can do is add the name and the password of the database to the script.
    I really need help.
    And thank you very very very much in advance

    [​IMG]
     
    aladinhw, Aug 1, 2009 IP
  2. Alice24

    Alice24 Greenhorn

    Messages:
    59
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #2
    it should be simple

    
    
    <? php
    
    // Connects to your Database 
    mysql_connect("Host", "user", "pass") or die(mysql_error()); 
    mysql_select_db("Database") or die(mysql_error());
    
    
    //This makes sure they did not leave any fields blank
    if (!$_POST['email'] | !$_POST['number'] | !$_POST['comment']  ) {
    die('Please Complete All the Fields.');
    }
    
    if (strpos($_POST['email'], '@') === false) {
        print 'This is not a valid email adress';
     }
    
    
    if (isset($_POST['add'])) { 
    
    // now we insert it into the database
    $insert = "INSERT INTO tb_users (email, number, comment )
    VALUES ('".$_POST['email']."' , '".$_POST['number']."'  , '".$_POST['comment']."'  )";
    
    $add_member = mysql_query($insert);
    
    
    }
    
    ?>
    
    <?php 
    echo("<p>Thank you for you're comment <p/>");
    } 
    else 
    { 
    ?>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    
    <input type="text" name="email" maxlength="20">
    <input type="text" name="number" maxlength="10">
    <input type="text" name="comment" cols="20" rows="10" maxlength="100">
    
    
    <input type="submit" name="add" value="Add">
    
    <?
    }
    ?>
    
    
    Code (markup):
     
    Last edited: Aug 1, 2009
    Alice24, Aug 1, 2009 IP
  3. aladinhw

    aladinhw Active Member

    Messages:
    337
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    68
    #3
    Thnk you but that didn't work
     
    aladinhw, Aug 1, 2009 IP
  4. ezprint2008

    ezprint2008 Well-Known Member

    Messages:
    611
    Likes Received:
    15
    Best Answers:
    2
    Trophy Points:
    140
    Digital Goods:
    1
    #4
    alad.. why dont you pay a PHP programmer to do this for you.
    These forums are for people that DO know PHP , but need help on their scripts and ideas.

    What youre doing is posting a "Hey, build my website and forms for free ..and by the way , this is a picture of how I want it to work. "

    What do you do for a living? .. send me the address and I'll drop off some diagrams of free stuff I want you to do for me.
     
    ezprint2008, Aug 1, 2009 IP
  5. aladinhw

    aladinhw Active Member

    Messages:
    337
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    68
    #5
    This is a community ,We are supposed to help each other. I always help people and The PHP that I am taking about is simple I guess. It's not something complicated. I expect people to help me like I help them. Anyway, If you want something from me then chek my Signature. You make the PHP script and I give you free services, If that ok with you.

    Thank you
     
    aladinhw, Aug 2, 2009 IP
  6. aladinhw

    aladinhw Active Member

    Messages:
    337
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    68
    #6
    hello everybody
    I found this script but the only problem is that It sends the message per E-mail. And since I am using a Free Hosting , that won't work. I need some modification on this script so it will send the informations directly to MySQL

    this is the script :
    <?php
    
    // ------------- CONFIGURABLE SECTION ------------------------
    
    // $mailto - set to the email address you want the form
    // sent to, eg
    //$mailto		= "youremailaddress@example.com" ;
    
    $mailto = 'my-email@gmail.com' ;
    
    // $subject - set to the Subject line of the email, eg
    //$subject	= "Feedback Form" ;
    
    $subject = "Feedback Form" ;
    
    // the pages to be displayed, eg
    //$formurl		= "http://www.example.com/feedback.html" ;
    //$errorurl		= "http://www.example.com/error.html" ;
    //$thankyouurl	= "http://www.example.com/thankyou.html" ;
    
    $formurl = "http://www.my-site.co.cc/" ;
    $errorurl = "http://www.my-site.co.cc/error.html" ;
    $thankyouurl = "http://www.my-site.co.cc/thankyou.html" ;
    
    $email_is_required = 1;
    $name_is_required = 1;
    $comments_is_required = 1;
    $uself = 0;
    $use_envsender = 0;
    $use_sendmailfrom = 0;
    $use_webmaster_email_for_from = 0;
    $use_utf8 = 1;
    $my_recaptcha_private_key = '' ;
    
    // -------------------- END OF CONFIGURABLE SECTION ---------------
    
    $headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ;
    $content_type = (!isset( $use_utf8 ) || ($use_utf8 == 0)) ? 'Content-Type: text/plain; charset="iso-8859-1"' : 'Content-Type: text/plain; charset="utf-8"' ;
    if (!isset( $use_envsender )) { $use_envsender = 0 ; }
    if (isset( $use_sendmailfrom ) && $use_sendmailfrom) {
    	ini_set( 'sendmail_from', $mailto );
    }
    $envsender = "-f$mailto" ;
    $fullname = (isset($_POST['fullname']))? $_POST['fullname'] : $_POST['name'] ;
    $email = $_POST['email'] ;
    $comments = $_POST['comments'] ;
    $http_referrer = getenv( "HTTP_REFERER" );
    
    if (!isset($_POST['email'])) {
    	header( "Location: $formurl" );
    	exit ;
    }
    if (($email_is_required && (empty($email) || !preg_match('/@/', $email))) || ($name_is_required && empty($fullname)) || ($comments_is_required && empty($comments))) {
    	header( "Location: $errorurl" );
    	exit ;
    }
    if ( preg_match( "/[\r\n]/", $fullname ) || preg_match( "/[\r\n]/", $email ) ) {
    	header( "Location: $errorurl" );
    	exit ;
    }
    if (strlen( $my_recaptcha_private_key )) {
    	require_once( 'recaptchalib.php' );
    	$resp = recaptcha_check_answer ( $my_recaptcha_private_key, $_SERVER['REMOTE_ADDR'], $_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field'] );
    	if (!$resp->is_valid) {
    		header( "Location: $errorurl" );
    		exit ;
    	}
    }
    if (empty($email)) {
    	$email = $mailto ;
    }
    $fromemail = (!isset( $use_webmaster_email_for_from ) || ($use_webmaster_email_for_from == 0)) ? $email : $mailto ;
    
    if (function_exists( 'get_magic_quotes_gpc' ) && get_magic_quotes_gpc()) {
    	$comments = stripslashes( $comments );
    }
    
    $messageproper =
    	"This message was sent from:\n" .
    	"$http_referrer\n" .
    	"------------------------------------------------------------\n" .
    	"Name of sender: $fullname\n" .
    	"Email of sender: $email\n" .
    	"------------------------- COMMENTS -------------------------\n\n" .
    	$comments .
    	"\n\n------------------------------------------------------------\n" ;
    
    $headers =
    	"From: \"$fullname\" <$fromemail>" . $headersep . "Reply-To: \"$fullname\" <$email>" . $headersep . "X-Mailer: chfeedback.php 2.15.0" .
    	$headersep . 'MIME-Version: 1.0' . $headersep . $content_type ;
    
    if ($use_envsender) {
    	mail($mailto, $subject, $messageproper, $headers, $envsender );
    }
    else {
    	mail($mailto, $subject, $messageproper, $headers );
    }
    header( "Location: $thankyouurl" );
    exit ;
    
    ?>
    
    Code (markup):
    and this is My form HTML :

    <html>
    <head>
    </head>
    <body>
    <form action="feedback.php" method="post">
    <table border="0" cellpadding="8" cellspacing="8" summary="feedback form">
    <tr><td><label for="tswname">Name</label>:</td><td><input type="text" name="fullname" id="tswname" size="25" /></td></tr>
    <tr><td><label for="tswemail">Email address</label>:</td><td><input type="text" id="tswemail" name="email" size="25" /></td></tr>
    <tr>
    <td colspan="2">
    <label for="tswcomments">Comments</label><br />
    <textarea rows="15" cols="45" name="comments" id="tswcomments"></textarea>
    </td>
    </tr>
    <tr>
    <td align="center" colspan="2">
    <input type="submit" value="Send Feedback" /><br />
    </td>
    </tr>
    </table>
    </form>
    
    </body>
    </html>
    Code (markup):
    P.S: My only problem is the first script , the second one is good but the first need changes so the information will be sent dirctly to MySQL

    Please help me

    thank you very much in advance
     
    aladinhw, Aug 2, 2009 IP
  7. aladinhw

    aladinhw Active Member

    Messages:
    337
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    68
    #7
    aladinhw, Aug 2, 2009 IP
  8. Alice24

    Alice24 Greenhorn

    Messages:
    59
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #8
    for nothing.
     
    Alice24, Aug 2, 2009 IP