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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 17

Thread: Few Questions

  1. #1
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Few Questions

    Hi there everyone, I'm a bit unsure if this is going to be the right forum you post these questions in, if it turns out to be incorrect I apologise.

    Basically I have a few tasks that I need to complete, I need to create a website(this isn't the problem) that contains a form for users to input their details. Once submitted the user details should then go to a database and an email of confirmation.

    I have some experience of coding having used, Pascal, C++, Python, Java but all too a very basic level.

    I was just wondering what I should use to complete these tasks and if someone could point me into the direction of some tutorials that may be of assistance.

    Cheers Ed

  • #2
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    Basically you need to use $_POST or $_GET depending on the form submission type (more than likely $_POST will be better suited) to get the data passed from the form to your script

    For mysql, you will need mysql_connect, mysql_select_db, mysql_query and mysql_real_escape_string (go to php.net/function_name_here for more info on them all)

    Finally to send the email you will need to use the mail() function.

    I would suggest you look at examples at http://www.w3schools.com/ for more information
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • Users who have thanked JAY6390 for this post:

    Edd1e316 (02-25-2010)

  • #3
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Ok is PHP definitely the way for me to approach this task then ?

    I've downloaded Visual Web Developer 2008 Express edition, to see if that is any use.

    My plan is too make the website in Photoshop CS4 and then use splicing tutorials.

    The form in PHP and MySQL ?? for the database side.

    Does that seem the best approach ?

  • #4
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    PHP is for processing. For the form generation you will need to create a form using HTML. I would definitely recommend using PHP for this. It's fairly simple to create a "contact form" or whatever kind of form you are generating. If you google php contact form tutorial I'm sure you will find a suitable tutorial that will show you how to do this, and from there modify it to a form more suitable to yours. After that its just a case of creating a simple database table to insert the data into before emailing
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #5
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Ok excellent thank you, I'll post back my progress in a couple of days.

  • #6
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I've just got round to fully installing Apache, PHP, MySQL and PHPmyadmin, proved to be alot more complex than any standard installation without alot of code editting.

    Anyways the real work will start now and I'll keep you updated with any queries that will no doubt arise.

  • #7
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts
    [PHP<?php

    mysql_connect("localhost","root","root") or die(mysql_error());
    mysql_select_db("customerquotation") or die(mysql_error());

    $fullname = $_POST['fullname'];
    $companyname = $_POST['companyname'];
    $telephonenumber = $_POST['telephonenumber'];
    $email = $_POST['email'];
    $jobdescription = $_POST['jobdescription'];
    $joblocation = $_POST['joblocation'];
    $hearabout = $_POST['hear'];

    //inserting data order
    $order = "INSERT INTO data_employees
    (fullname, companyname, telephonenumber)
    VALUES
    ('$fullname',
    '$companyname',
    '$telephonenumber')";

    //declare in the order variable
    $result = mysql_query($order); //order executes
    if($result){
    echo("<br>Input data is succeed");
    } else{
    echo("<br>Input data is fail");
    }
    ?>[/PHP]

    Thats my coding, I want the data entered in a form to go into a mysql database any way you could help me out guys and girls ?

  • #8
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    What's the problem with the code you've posted? Also, check the docs for mysql_real_escape_string, intval etc on the PHP site. You really need to sanitise and validate your input.

  • #9
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts
    It won't add the data to the database no matter what solutions I've tried proper annoying.

  • #10
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    It prints the message to say that data entry failed?

  • #11
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts
    <?php
    $con = mysql_connect("localhost","root","root");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }

    mysql_select_db("customerquotation", $con);

    $sql="INSERT INTO customers (fullname, companyname, telephone, email, jobdescription, joblocation, hear)
    VALUES
    ('$_POST[fullname]','$_POST[companyname]','$_POST[telephone]','$_POST[email]','$_POST[jobdescription]','$_POST[joblocation]','$_POST[hear]')";

    if (!mysql_query($sql,$con))
    {
    die('Error: ' . mysql_error());
    }
    echo "1 record added";

    mysql_close($con)
    ?>

    It's finally adding data to the database in all the fields except the first three were I get the following error messages...

    Notice: Undefined index: fullname in C:\server\www\myserver.dev\public_html\quotationform.php on line 12

    Notice: Undefined index: companyname in C:\server\www\myserver.dev\public_html\quotationform.php on line 12

    Notice: Undefined index: telephone in C:\server\www\myserver.dev\public_html\quotationform.php on line 12

  • #12
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Are you using an isset form POST method? Try this

    PHP Code:
    <?php

    mysql_connect
    ("localhost","root","root") or die(mysql_error());
    mysql_select_db("customerquotation") or die(mysql_error());

    if (isset(
    $_POST['submit']))

    {

    $fullname $_POST['fullname'];
    $companyname $_POST['companyname'];
    $telephonenumber $_POST['telephonenumber'];
    $email $_POST['email'];
    $jobdescription $_POST['jobdescription'];
    $joblocation $_POST['joblocation'];
    $hearabout $_POST['hear'];

    //inserting data order
    $order "INSERT INTO data_employees
    (fullname, companyname, telephonenumber)
    VALUES
    ('$fullname',
    '$companyname',
    '$telephonenumber')"
    ;

    //declare in the order variable
    $result mysql_query($order); //order executes
    if($result){
    echo(
    "<br>Input data is succeed");
    } else{
    echo(
    "<br>Input data is fail");
    }

    }

    else {
    //Form goes here
    }
    ?>
    Place your form into the else statement. If your form is in a different file, than remove the else and keep the IF ISSET
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • #13
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I've tried your coding and with no success.

    The coding I posted in my previous post is what I'm having the most success with except it won't enter the data of the first three fields for some unknown reason, once I've cracked that I'll be on my way to validating it all and I'll be done.

  • #14
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    As I mentioned earlier, sanitise and validate. If you were validating, there would be no possibility of it attempting to insert nonexistent fields. You should be doing something along the lines of the following, (same for each POST var):

    Code:
    if (isset($_POST['companyname']) && !empty($_POST['companyname']))
    {
        [sanitise and assign the var here as you've checked it's set]
    }
    else
    {
        [do your error processing here, as companyname isn't set]
    }

    Plus, I'll mention again, sanitise and validate. Read up on the use of mysql_real_escape_string.
    Last edited by MattF; 03-31-2010 at 04:42 AM.

  • #15
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts
    <?php

    $con = mysql_connect("localhost","root","root");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }

    $fullname = check_input($_POST['fullname']);
    $companyname = check_input($_POST['companyname']);
    $telephone = check_input($_POST['telephone']);
    $email = check_input($_POST['email']);
    $jobdescription = check_input($_POST['jobdescription']);
    $joblocation = check_input($_POST['joblocation']);
    $hear = check_input($_POST['hear']);

    mysql_select_db("customerquotation", $con);

    $sql="INSERT INTO customers (fullname, companyname, telephone, email, jobdescription, joblocation, hear)
    VALUES
    ('$_POST[fullname]','$_POST[companyname]','$_POST[telephone]','$_POST[email]','$_POST[jobdescription]','$_POST[joblocation]','$_POST[hear]')";

    if (!mysql_query($sql,$con))
    {
    die('Error: ' . mysql_error());
    }
    echo "1 record added";

    mysql_close($con)
    ?>

    <?php
    function check_input($data)
    {
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
    }
    ?>

    Thats what I went for in the end and seems to work fine can anyone foresee any problems with that coding ?

    I've got the validation in the html of the website and that is using JavaScript


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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