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 12 of 12
  1. #1
    New to the CF scene
    Join Date
    Dec 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Resolved Form "submit" issues

    Hey all, new to the forum. Love it so far.

    I have been trying to build a form for my new website. When the submit button is clicked, it will run a php file which will send the form input to a mysql database.

    I have tested the php file and it communicates fine with the db, but I think I have issues within the form html because the info does not get inputted. I was hoping you guys could take a look at my code to see if you can identify any problems. Thanks. Here's the form html:

    <form id="form" form method="post" action="insertbrewpub.php">
    <div class="success">Contact form submitted!<br>
    <strong>We will be in touch soon.</strong> </div>
    <fieldset>
    <label class="name">
    <input type="text" value="Name:">
    <span class="error error-empty">*This is not a valid name.</span><span class="empty error-empty">*This field is required.</span> </label>
    <label class="address">
    <input type="text" value="Address:">
    <span class="error error-empty">*This is not a valid email address.</span><span class="empty error-empty">*This field is required.</span> </label>
    <label class="city">
    <input type="text" value="City:">
    <span class="error error-empty">*This is not a valid city.</span><span class="empty error-empty">*This field is required.</span> </label>
    <label class="phone">
    <input type="tel" value="Phone:">
    <span class="error error-empty">*This is not a valid phone number.</span><span class="empty error-empty">*This field is required.</span> </label>
    <label class="website">
    <input type="url" value="Website:">
    </label>
    <label class="description">
    <textarea>Description:</textarea>
    <span class="error">*The message is too short.</span> <span class="empty">*This field is required.</span> </label>

    <div class="btns"><div class="heading-wrapper-center button-bg"><div class="heading"><a data-type="reset" class="button right-1" href="#"><strong>clear</strong></a><a data-type="submit" class="button" input type="submit"><strong>submit brewpub</strong></a></div></div></div>
    </fieldset>
    </form>
    Last edited by roxslide; 12-28-2012 at 10:26 PM.

  • #2
    Regular Coder
    Join Date
    Jul 2012
    Location
    London
    Posts
    473
    Thanks
    4
    Thanked 86 Times in 86 Posts
    Can I see your PHP code.

  • #3
    New to the CF scene
    Join Date
    Dec 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You bet, here it is.....

    <?php
    $con = mysql_connect("localhost","dbname","dbpassword");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }

    mysql_select_db("dbname", $con);

    $sql="INSERT INTO brewpubs (Name, Address, City, Phone, Website)
    VALUES
    ('$_POST[Name]','$_POST[Address]','$_POST[City]','$_POST[Phone]','$_POST[Website]')";

    if (!mysql_query($sql,$con))
    {
    die('Error: ' . mysql_error());
    }
    echo "Your brewpub has been added to the database";

    mysql_close($con);
    ?>

  • #4
    Regular Coder
    Join Date
    Jul 2012
    Location
    London
    Posts
    473
    Thanks
    4
    Thanked 86 Times in 86 Posts
    Try:

    New HTML
    Code:
    <html>
    <head>
    	<title>Index</title>
    </head>
    <body>
    <form id='form' method='post' action='insertbrewpub.php'>
    <fieldset>
    <legend>Contact us</legend>
    <p> All fields with * are required</p>
     
    <input type='hidden' name='submitted' id='submitted' value='1'/>
     
        <label for='name' >Your Full Name*: </label><br/>
        <input type='text' name='name' id='name'  maxlength="50" /><br/>
     
        <label for='email' >Address*:</label><br/>
        <input type='text' name='address' id='address' maxlength="200" /><br/>
     
        <label for='email' >City*:</label><br/>
        <input type='text' name='city' id='city' maxlength="50" /><br/>
     
        <label for='phone' >Phone Number:</label><br/>
        <input type='text' name='phone' id='phone' maxlength="15" /><br/>
     
        <label for='phone' >Website:</label><br/>
        <input type='text' name='website' id='website' maxlength="200" /><br/>
     
        <input type='submit' name='Submit' value='Submit' />
     
    </fieldset>
    </form>
    <div class="success"></div>
    </body>
    </html>
    PHP Code:
    <?php
        
    $con 
    mysql_connect("host""db-user""database-pw");
    if (!
    $con)
    {
    die(
    'Could not connect: ' mysql_error());
    }

    mysql_select_db("a1853017_test2"$con);

    $sql="INSERT INTO brewpubs (`Name`, `Address`, `City`, `Phone`, `Website`)
    VALUES
    ('$_POST[name]','$_POST[address]','$_POST[city]','$_POST[phone]','$_POST[website]')"
    ;

    if (!
    mysql_query($sql,$con)) {
        die(
    'Error: ' mysql_error());
    }
    echo 
    "Information added to the database";

    function 
    ProcessForm()
     {
         if(!isset(
    $_POST['submitted']))
         {
            return 
    false;
         }

    mysql_close($con);
    }
    ?>
    Edited: New PHP code now fully working: http://dev.tempz.webatu.com/test2/ < Preview
    Last edited by tempz; 12-28-2012 at 12:59 AM.

  • #5
    Regular Coder
    Join Date
    Jul 2012
    Location
    London
    Posts
    473
    Thanks
    4
    Thanked 86 Times in 86 Posts
    SQL - If wanted:

    Code:
    CREATE TABLE `brewpubs` (
      `Name` varchar(50) COLLATE latin1_general_ci DEFAULT NULL,
      `Address` varchar(200) COLLATE latin1_general_ci DEFAULT NULL,
      `City` varchar(50) COLLATE latin1_general_ci DEFAULT NULL,
      `Phone` varchar(15) COLLATE latin1_general_ci DEFAULT NULL,
      `Website` varchar(200) COLLATE latin1_general_ci DEFAULT NULL,
      UNIQUE KEY `Name` (`Name`,`Phone`),
      FULLTEXT KEY `Name_2` (`Name`),
      FULLTEXT KEY `Name_3` (`Name`,`Address`,`City`,`Phone`,`Website`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;

  • #6
    Regular Coder
    Join Date
    Jul 2012
    Location
    London
    Posts
    473
    Thanks
    4
    Thanked 86 Times in 86 Posts
    Fix if left blank;

    PHP Code:
    <?php
        
    $con 
    mysql_connect("localhost""user""password");


    if (!
    $con)
    {
    die(
    'Could not connect: ' mysql_error());
    }

    mysql_select_db("a1853017_test2"$con);

    if(empty(
    $_POST['address'])) {
        echo 
    "<div class='error'>Please fill all fields with * - Go back </div>"; } else {

    $sql="INSERT INTO brewpubs (`Name`, `Address`, `City`, `Phone`, `Website`)

    VALUES
    ('$_POST[name]','$_POST[address]','$_POST[city]','$_POST[phone]','$_POST[website]')"
    ;

    if (!
    mysql_query($sql,$con)) {
        die(
    'Error: ' mysql_error());
    }
    echo 
    "Information added to the database";

    mysql_close($con);
    exit(); 

    ?>

  • #7
    New to the CF scene
    Join Date
    Dec 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Tempz......I really appreciate the help. I am a newbie and get confused pretty easy. It might help if I give you a link to the form:

    http://www.roxslide.com/brewpubform

    I believe the issue is somewhere in the section where I am putting the input type, etc with the code for the formatted buttons code....if that makes sense?

  • #8
    New to the CF scene
    Join Date
    Dec 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Tempz......i took some of your code and altered my form. The form now works (see link posted above) but I have lost the formatting for my buttons.

    When i add the following formatting for the buttons, the form stops working:

    div class="btns"><div class="heading-wrapper-center button-bg"><div class="heading"><a data-type="reset" class="button right-1" href="#"><strong>clear</strong></a><a data-type="submit" class="button" input type="submit"><strong>submit brewpub</strong></a></div></div></div>

    Any ideas? Do I need to construct the code differently for the buttons/submt function?

    Thanks

  • #9
    Regular Coder
    Join Date
    Jul 2012
    Location
    London
    Posts
    473
    Thanks
    4
    Thanked 86 Times in 86 Posts
    Try:

    Code:
    <input type="submit" class="myclass" value="Submit"> | <input type="reset" class="myclass" value="Reset!">
    or without classes, target these two.
    Code:
    input[type=submit] {
       /* Awesome styling */
    }
    input[type=reset] {
       /* Awesome styling */
    }

  • #10
    Regular Coder
    Join Date
    Jul 2012
    Location
    London
    Posts
    473
    Thanks
    4
    Thanked 86 Times in 86 Posts
    Also you should add a anti spam filter to the form.

  • #11
    New to the CF scene
    Join Date
    Dec 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for all of the help. I finally got the form working.........now I only have one other issue but it is php related so I posted it in the appropriate forum.

    Once again, thanks for all of the help.

  • #12
    Regular Coder
    Join Date
    Jul 2012
    Location
    London
    Posts
    473
    Thanks
    4
    Thanked 86 Times in 86 Posts
    Quote Originally Posted by Keven545 View Post
    Tempz......I really appreciate the help. I am a newbie and get confused pretty easy.

    You're welcome, check out my dev site for updates: http://dev.tempz.webatu.com


  •  

    Posting Permissions

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