Go Back   CodingForums.com > :: Client side development > HTML & CSS

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-27-2012, 09:48 PM   PM User | #1
roxslide
New to the CF scene

 
Join Date: Dec 2012
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
roxslide is an unknown quantity at this point
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 09:26 PM..
roxslide is offline   Reply With Quote
Old 12-27-2012, 10:43 PM   PM User | #2
tempz
Regular Coder

 
Join Date: Jul 2012
Location: London
Posts: 436
Thanks: 4
Thanked 80 Times in 80 Posts
tempz is an unknown quantity at this point
Can I see your PHP code.
tempz is offline   Reply With Quote
Old 12-27-2012, 10:52 PM   PM User | #3
roxslide
New to the CF scene

 
Join Date: Dec 2012
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
roxslide is an unknown quantity at this point
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);
?>
roxslide is offline   Reply With Quote
Old 12-27-2012, 11:36 PM   PM User | #4
tempz
Regular Coder

 
Join Date: Jul 2012
Location: London
Posts: 436
Thanks: 4
Thanked 80 Times in 80 Posts
tempz is an unknown quantity at this point
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-27-2012 at 11:59 PM..
tempz is offline   Reply With Quote
Old 12-27-2012, 11:58 PM   PM User | #5
tempz
Regular Coder

 
Join Date: Jul 2012
Location: London
Posts: 436
Thanks: 4
Thanked 80 Times in 80 Posts
tempz is an unknown quantity at this point
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;
tempz is offline   Reply With Quote
Old 12-28-2012, 12:21 AM   PM User | #6
tempz
Regular Coder

 
Join Date: Jul 2012
Location: London
Posts: 436
Thanks: 4
Thanked 80 Times in 80 Posts
tempz is an unknown quantity at this point
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(); 

?>
tempz is offline   Reply With Quote
Old 12-28-2012, 12:39 AM   PM User | #7
roxslide
New to the CF scene

 
Join Date: Dec 2012
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
roxslide is an unknown quantity at this point
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?
roxslide is offline   Reply With Quote
Old 12-28-2012, 02:35 PM   PM User | #8
roxslide
New to the CF scene

 
Join Date: Dec 2012
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
roxslide is an unknown quantity at this point
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
roxslide is offline   Reply With Quote
Old 12-28-2012, 06:15 PM   PM User | #9
tempz
Regular Coder

 
Join Date: Jul 2012
Location: London
Posts: 436
Thanks: 4
Thanked 80 Times in 80 Posts
tempz is an unknown quantity at this point
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 */
}
tempz is offline   Reply With Quote
Old 12-28-2012, 07:15 PM   PM User | #10
tempz
Regular Coder

 
Join Date: Jul 2012
Location: London
Posts: 436
Thanks: 4
Thanked 80 Times in 80 Posts
tempz is an unknown quantity at this point
Also you should add a anti spam filter to the form.
tempz is offline   Reply With Quote
Old 12-28-2012, 09:18 PM   PM User | #11
roxslide
New to the CF scene

 
Join Date: Dec 2012
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
roxslide is an unknown quantity at this point
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.
roxslide is offline   Reply With Quote
Old 12-29-2012, 03:24 AM   PM User | #12
tempz
Regular Coder

 
Join Date: Jul 2012
Location: London
Posts: 436
Thanks: 4
Thanked 80 Times in 80 Posts
tempz is an unknown quantity at this point
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
tempz is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:12 PM.


Advertisement
Log in to turn off these ads.