PDA

View Full Version : Connecting form to phpMyAdmin database on Godaddy.com


Chrismc
07-13-2013, 03:52 AM
I am working on a web site for my father. I have a contact form I created in dreamweaver. Right now it sends an email to him once it is filled out. I need the form to also send the filled out information to his database on Godaddy.com. I have already created some tables in phpMyAdmin for the information to go in. I just need the info from the form to be sent there. I am aware that it involves some coding, but I am a beginner in that area. I am not sure what I need to do next. Any help I can get would be much appreciated. Thanks.

Christie

edbr
07-13-2013, 04:16 AM
need a way to connect to the database, and an insert script. you can get the connection details from your hosting and user password that the data base will use

Chrismc
07-13-2013, 04:57 AM
godaddy hosts the website and supplied the database. All my files for the site are already at godaddy. I have the hosting username and password. What would the insert script be that I need? Where would I need to post that script?

edbr
07-13-2013, 05:58 AM
databases need permission and have user andpassword and you must edit permissions. if godaddy uses cpanel you should see a mysql link near the phpadmin link

as for the script , you will need to add the insert into the mail handling script

Chrismc
07-13-2013, 04:27 PM
Unfortunately, godaddy does not use cpanel. They use something called cloud hosting. I am very inexperienced in databases. I have read a book on mysql and one one phpMyAdmin. I got as far as setting up the tables and setting some of the parameters for the columns. The coding part I only slightly understand.

edbr
07-14-2013, 02:39 AM
ok but there still should be provision for giving permission for databases. as for inserting into a database its not that tricky but i suspect as you have a mailing script it wont be possible to use dreamweavers script wizard but we can probably help.
i will post a simple example of connect and insert when i have time omn Monday.
I usually recommend a look at tizag.com for tutorials as I think they give clear examples but also there are tutorials in the tut section on this forum

Chrismc
07-14-2013, 02:54 AM
Thank you. I have attached a few screen shots of what my php looks like and the options I have once I sign in. From what I have been researching it looks as though I need to create some setup script so my database can connect with my Dad's website form. Then I need to give it directions on how to receive the form. My first problem is I don't know where to go to setup the script or what to put in the script to make the connection. Then I am not sure on the directions to give it. I will look for your post on Monday. In the meantime I will look into tizag.com you mentioned. Thanks again for your help.

edbr
07-14-2013, 03:07 AM
that looks like phpadmin, there is usually a different wat to give permissions on a server . i just have no experoience with godaddy but maybe someone else will. if i get timne ill have a look if they give some instruction

Chrismc
07-14-2013, 03:14 AM
Thanks for offering to take a look when you get some time. I have also attached the contact form I set up in dreamweaver. When info gets submitted to this form I will need to have it not only go to my fathers email, (which it does now) but also get sent to the database.

edbr
07-14-2013, 03:17 AM
they talk of a database publishing wizard, so it looks like it maybe that way, my eyes glazed over when i tried reading it. they should be able to help. I wonder if they allow a msqlite database?
I am now sure i would never use godaddy

edbr
07-14-2013, 03:23 AM
hold the phone read this
http://support.godaddy.com/help/article/36/creating-mysql-or-sql-server-databases-for-your-hosting-account

Chrismc
07-14-2013, 03:28 AM
Well it was my father's choice to go with them. Initially, he has asked me to make him a web page since I took a class in school. We used dreamweaver there. I told him it was a beginners class, so I could make a decent functioning one, but beyond that I would have to learn more. So I got it finished up and running. I even taught myself how to create a form and have it send replies to his email. I never learned that in class. Then he wanted a blog. I told him I could set him up one on wordpress cause it was free and created a link from his site on dreamweaver to that. I did that, then helped him set up his blog on wordpress and taught him how to use it. Now he wants a database. I am impressed with myself for figuring all this out so far. I don't think he realizes how much work goes into this. Anyway, he's my Dad and I want to help him. So, I will try and look into the database publishing wizard. Thanks again for your help.

Chrismc
07-14-2013, 03:44 AM
Yeah, I have the database created already. I made tables and columns for the tables. It just isn't connected to my Dad's site yet. That's what I can't figure out how to do.

edbr
07-14-2013, 05:15 AM
ok actually i noticed they gave you a connection and select example in their help guide. i sill advise a look at the examples i mentioned though

edbr
07-14-2013, 05:18 AM
$myhost = "localhost";
$mydb = "MYDATABASE";
$mydbuser = "MYUSER";
$mydbpass = "MYPASSWORD";

$db = mysql_connect($myhost, $mydbuser, $mydbpass)
or die ("UNABLE TO CONNECT TO DATABASE");
mysql_select_db($mydb)
or die ("UNABLE TO SELECT DATABASE");

SEASON TO TASTE

Chrismc
07-14-2013, 03:50 PM
Would I post this script with my information inserted in the appropriate places inside the contact form script I sent you, or before or after it, or some place else?

edbr
07-15-2013, 02:24 AM
the insert query would need to fire as the mail is sent , after the validation etc so a lot depends on your mail handling script.
typicaliy you will have a block if{
which checks all the headers have been submitted

tux
07-15-2013, 02:16 PM
Hello Chris,

Welcome to the forum. I can see where you are coming from with this. I was in your shoes a few years back and building a website for my brother with very little experience.

You really need to try to learn a bit more. I found it increasingly hard as more function was asked for.

I will help when I have time as will others on here but a great resource that I have found really helpful is...

https://www.phpacademy.org/

When I have time I will dig out a script that does just as you have asked. You can then pick through it and adapt it to your needs.

Oh, when you post any scripts, copy the code and wrap in code tags instead of posting image attachments. We can copy and paste it to amend as needed.

Regards, Paul

Chrismc
07-15-2013, 05:55 PM
Thank you Paul. I appreciate it.

tux
07-16-2013, 09:53 PM
Sorry for the delay Chris, been really busy and only do this stuff as a bit of a hobby.

Okay, I have dug out and modified a script I used quite a while ago that should help you. It could probably do with a bit of updating especially the error handling but should get you on the right track. It does not include any sql injection protection so your should look into that. phpacademy.org has a good tutorial on the subject.

Not sure how you currently have this set up but this takes 4 files. They all need to be in your root folder.

The 4 files are: contact.php, contact_submit.php, class.phpmailer.php & class.smtp.php and are attached as a zip file.

Contact.php is the form (not formatted so ugly at the momment), contact_submit.php processes the form, sends the email and adds the data to the database. The other 2 files are required by script.

I have commented out the script to try to explain it to you and stated where you need to add your own info like database username and password etc. and email username and password.

I hope you can make sense of it all, let me know if you run into any issues.

Regards, Paul

Chrismc
07-17-2013, 03:31 PM
No worries about the delay. I appreciate your help. I will take a look at that and let you know if I have any further questions. Thanks again.

Christie

Chrismc
07-17-2013, 04:29 PM
The contact form I have already, should I just scrap it and use yours? Then with yours take out the fields I don't need. In my original one I just had: Name, Email, Comment and a submit and reset button.
Also, at godaddy in my dad's root folder, there is already a gdform.php.


<?php
$request_method = $_SERVER["REQUEST_METHOD"];
if($request_method == "GET"){
$query_vars = $_GET;
} elseif ($request_method == "POST"){
$query_vars = $_POST;
}
reset($query_vars);
$t = date("U");

$file = $_SERVER['DOCUMENT_ROOT'] . "/../data/gdform_" . $t;
$fp = fopen($file,"w");
while (list ($key, $val) = each ($query_vars)) {
fputs($fp,"<GDFORM_VARIABLE NAME=$key START>\n");
fputs($fp,"$val\n");
fputs($fp,"<GDFORM_VARIABLE NAME=$key END>\n");
if ($key == "redirect") { $landing_page = $val;}
}
fclose($fp);
if ($landing_page != ""){
header("Location: http://".$_SERVER["HTTP_HOST"]."/$landing_page");
} else {
header("Location: http://".$_SERVER["HTTP_HOST"]."/");
}


?>


Do I need to scrap the gdform.php also and use yours as well?

In his root folder is also a webformmailer.php, but the contact form I use isn't connected to that one. Earlier I was trying to get his form mail to work and tried different things. When I talked to a person at godaddy i asked if I needed to remove it from the root folder, they said it would be okay to leave it since it is not connected to anything.

You mentioned that all 4 forms need to be in his root folder. The contact form I have currently is incorporated into the html on his Free Trial page which by default is in his root folder.(Depending on whether I keep some of what I have or use all of what you sent) Aside from the contact form you added in the folder you sent me, do I just make adjustments to the other php files and upload them to the server as separate documents?

edbr
07-18-2013, 02:00 AM
that is a very simple generic form so try tux's offering. actually i havent looked at it but an sure Tux wouldn't send you a lemon. especially if it incubes some better security in string slashes and some email validation

tux
07-18-2013, 03:46 PM
As long as the files are in the same folder you should be okay. If not you will have to declare the full path to the files.

You are can use your own form, just point the action to contact_submit.php. If you want to use the error handling you will need to add the code at the top of the contact.php file and echo out the $error variables where you want them to show.

As I mentioned earlier you will need to add some more security to be on the safe side. Rather than me try to explain check out the videos at PHP Academy here...

https://phpacademy.org/course/php-security

Let know how you get on and if you come across something that you don't understand and I will try to help further.

Regards, Paul

Edbr, does this want moving to the PHP forum?

Chrismc
07-18-2013, 05:25 PM
Thank you very much both of you! I need to customize the contact_submit.php to match up with the fields i have in dreamweaver and delete fields I don't have correct? For instance, I have a text field named "clientname". In the contact_submit.php it has one called 'firstname' and 'lastname' I can delete one of those and change the other to 'clientname' correct?
Also, before I upload the form to my root folder, I need to delete the instructions added beside some of the sections in the form, right? For instance, where you say, " This is used with the redirect to greet the user with their name", I should delete that, right?

tux
07-18-2013, 05:34 PM
Yes, change and delete the fields as needed in the form and adjust the code in contact_submit to suit.

The instructions are commented out with slashes (//) so will not be read by the server so can stay.

You will need to insert your own info into the script where required though.

Chrismc
07-18-2013, 05:44 PM
Thanks. I am using my brother's server. Should I put the FTP address under the spot where it says local host or should I leave it local host?

tux
07-18-2013, 05:46 PM
localhost should be okay!

Chrismc
07-18-2013, 06:22 PM
I think I have the contact_submit form just about done, need to ask my dad for his email username and pw. Do I need to make any adjustments to the class.smtp.php form, or just upload that one? Also, what do I need to edit in the class.phpmailer.php, is there anything?

tux
07-18-2013, 06:30 PM
No you only need to play with the 2 contact files. Don't touch the others just upload them.

You could just use your own email settings while you test it all is working rather than keep sending your dad test emails. Then change them to his later.

Chrismc
07-18-2013, 06:41 PM
That's a good idea. I am going to stick to my own contact form though. I will just change the action to contact_submit.php. So, I only need to play with the one contact form, contact_submit.php, right?

tux
07-18-2013, 06:50 PM
In contact.php you will also have to add the error handling code!

Chrismc
07-18-2013, 07:03 PM
So, I need to use the contact.php you sent me, don't change it at all but add error handling code, and still keep my own form on my dreamweaver page too? Or just add the error handling code to my own contact form on my dreamweaver page?
What is the error handling code I should use? On my contact form on my Free trial page I have used validations for the name, and email fields. Is error handling code similar to that but for the database?

tux
07-18-2013, 07:13 PM
You can still use your own contact.php file but at the top of the page add the error handling code.... this


<?php

$do = $_GET['do'];
$firstname = $_GET['name'];

if($do == "y"){
$thankyou = "<span class=\"success\">Thank you " . $firstname . ", your message has been sent.</span>";
$error = "";
$fail = "";
$spamfail = "";
}elseif($do == "fail"){
$fail = "Your message wasn't sent ". $firstname .". An error occured, please try again.";
$thankyou = "";
$error = "";
$spamfail = "";
}elseif($do == "n"){
$error = "Your message wasn't sent ". $firstname .". Be sure all fields are complete and try again!";
$thankyou = "";
$fail = "";
$spamfail = "";
}elseif($do == "spamfail"){
$spamfail = "Your message wasn't sent ". $firstname .". Be sure to get your maths correct!";
$thankyou = "";
$fail = "";
$error = "";
}

?>


..... and somewhere on the page add this......

<?php echo $thankyou; ?><?php echo $error; ?><?php echo $spamfail; ?>

.... to echo out the errors.

tux
07-18-2013, 07:15 PM
The error handling is a bit rough as I did it ages ago. Nowadays, I would use an array() and functions but that is something you can learn about later once you have this done.

Chrismc
07-18-2013, 07:27 PM
In dreamweaver at the top of the code where you said to insert the error handling, should I add it Below the end of the </script> for validating the form, or above it just below </style>?

tux
07-18-2013, 07:33 PM
The first block of code needs to go at the top before any of your html, you wont need the php tags as you will already have them.

The other single line of code will go in the body of your page where you want the errors to be displayed.

Chrismc
07-18-2013, 08:47 PM
By this: "The first block of code needs to go at the top before any of your html, you wont need the php tags as you will already have them", you mean I can delete what script I have at the top of my code and just put in the info I customized before any of the html?

By this: "The other single line of code will go in the body of your page where you want the errors to be displayed", you mean put this inside my contact form php at the bottom?

Chrismc
07-18-2013, 09:45 PM
With this string of code

$fname = $_POST['firstname']; //THIS IS USED WITH THE REDIRECT TO GREET THE USER WITH THEIR NAME

should I use 'clientname' - in my contact form clientname is the ID and the value is Name.
Should I make $fname - $cname ?

tux
07-18-2013, 09:56 PM
Post your contact.php code in full, all of it from the first php tag until the last html tag.

I will check in case there is anything in it that may be needed.

Chrismc
07-18-2013, 10:02 PM
I haven't added anything to it as of yet. But, here it is as of now:


</p>

<table width="100%" border="0" cellpadding="5" bgcolor="#CCCCCC" id="contactform">
<tr>
<td width="20%" height="228"><form action="gdform.php" method="post" enctype="enctype=&quot;text/plain&quot;" name="contactform" id="contactform">
<p align="right">
<label><span class="textinform">
Name:<br />
</span></label>
</p>
<p align="right">
<span class="textinform">
<label>Email:<br />
<br />
</label>
</span></p>
<p align="right">
<span class="textinform">
<label>Comment:</label>
</span></p>
<p align="right"><br />
<br />
</p>
<p align="right"><br />
</p>
</form></td>
<td width="80%"><form id="form2" name="form2" method="post" action="">
<p>
<input name="clientname" type="text" id="clientname" size="45" />
</p>
<p>
<input name="email" type="text" id="email" size="25" />
</p>
<p>
<textarea name="comments" id="comments" cols="75" rows="5"></textarea>
</p>
<p>
<label>
<input name="button" type="submit" id="button" onclick="MM_validateForm('clientname','','R','email','','Ri sEmail');return document.MM_returnValue" value="Submit" />
<input type="reset" name="button2" id="button2" value="Reset" />
</label>
</p>
</form>
<form id="form1" name="form1" method="post" action="">
<input type="hidden" name="hiddenField" id="hiddenField" />
</form></td>
</tr>
</table>

tux
07-18-2013, 10:16 PM
Chris, copy all of the code from the <html> to </html> and anything above it.

tux
07-18-2013, 10:18 PM
you need to avoid using tables, they are only really used for displaying data nowadays. You should be using CSS to style your website.

tux
07-18-2013, 10:19 PM
Also, do you have a link to where it is live right now?

Chrismc
07-18-2013, 10:23 PM
I originally didn't have tables. My brother mentioned lining things up in two columns and suggested the tables. My Dad, who I made the site for, liked the idea and said to do it. Which is why there are tables.

Here is the code from the beginning of the html, to the end:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Free Trial - Contact Me</title>
<link href="deansindex.css" rel="stylesheet" type="text/css" />
<style type="text/css">
</style>
<script type="text/javascript">
function MM_validateForm() { //v4.0
if (document.getElementById){
var i,p,q,nm,test,num,min,max,errors='',args=MM_valida teForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
if (val) { nm=val.name; if ((val=val.value)!="") {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
} else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
} if (errors) alert('The following error(s) occurred:\n'+errors);
document.MM_returnValue = (errors == '');
} }
</script>
</head>

<body>

<div id="wrap">
<div class="freetrialheaderbox"><img src="Images/freetrialheader.png" width="915" height="200" /></div>



<div class="buttonbox">

<a href="index.html"><div class="homebutton"><img src="Images/homebuttonresized.png" width="73" height="56" /></div></a><!--end homebutton-->

<a href="misson.html"><div class="missionbutton"><img src="Images/missionbuttonresized.png" width="90" height="56" /></div></a><!--end missionbutton-->

<a href="meditation.html"><div class="meditationbuton"><img src="Images/Meditationbuttonresized.png" width="114" height="56" /></div></a><!--end meditationbutton-->

<a href="freetrial.html"><div class="freetrialbutton"><img src="Images/freetrialbuttonresized.png" width="114" height="56" /></div></a><!--end freetrialbutton-->

<a href="rates.html"><div class="ratesbutton"><img src="Images/ratesbuttonresized.png" width="74" height="56" /></div></a><!--end ratesbutton-->

<a href="blog.html"><div class="blogbutton"><img src="Images/blogbuttonresized.png" width="64" height="56" /></div></a><!--end blogbutton-->

<a href="credentials.html"><div class="credentialsbutton"><img src="Images/credentialsbuttonresized.png" width="114" height="56" /></div></a><!--end credentialsbutton-->

<a href="library.html"><div class="librarybutton"><img src="Images/librarybuttonresized.png" width="86" height="56" /></div></a><!--end librarybutton-->

</div><!--end buttonbox-->

<div class="body">

<div class="freetrialparagraphbox"><img src="Images/freetrial.png" width="915" height="225" /></div>
<p><!--end freetrialparagraphbox-->


<div class="freetrialimagebox"></div><!--end freetrialimagebox-->


<strong><strong><center> Fill Out This Free Trial Form:</center></strong><strong>


</p>

<table width="100%" border="0" cellpadding="5" bgcolor="#CCCCCC" id="contactform">
<tr>
<td width="20%" height="228"><form action="gdform.php" method="post" enctype="enctype=&quot;text/plain&quot;" name="contactform" id="contactform">
<p align="right">
<label><span class="textinform">
Name:<br />
</span></label>
</p>
<p align="right">
<span class="textinform">
<label>Email:<br />
<br />
</label>
</span></p>
<p align="right">
<span class="textinform">
<label>Comment:</label>
</span></p>
<p align="right"><br />
<br />
</p>
<p align="right"><br />
</p>
</form></td>
<td width="80%"><form id="form2" name="form2" method="post" action="">
<p>
<input name="clientname" type="text" id="clientname" size="45" />
</p>
<p>
<input name="email" type="text" id="email" size="25" />
</p>
<p>
<textarea name="comments" id="comments" cols="75" rows="5"></textarea>
</p>
<p>
<label>
<input name="button" type="submit" id="button" onclick="MM_validateForm('clientname','','R','email','','Ri sEmail');return document.MM_returnValue" value="Submit" />
<input type="reset" name="button2" id="button2" value="Reset" />
</label>
</p>
</form>
<form id="form1" name="form1" method="post" action="">
<input type="hidden" name="hiddenField" id="hiddenField" />
</form></td>
</tr>
</table>
<div class="mycreditmessagefreetrialpage">Designed by: Christie McCormick: cmdesign.co</div><!--end myscreditmessagefreetrialpage-->


</div><!--end body-->
</div><!--end wrap-->


</body>
</html>

tux
07-18-2013, 10:32 PM
If that is the full code of the page and there is nothing above the <!doctype> then add the first block above it before the <!doctype> and including the php tags ( <?php and ?> )

The single line of code can go anywhere that you want it to appear on the page, usually above the form.

Tables really are not a good idea, you can line it all up and make it look great with CSS. Here is a link for a bit of an insight into styling forms with CSS. I'll let you figure it out but get rid of the tables :)

http://www.webcredible.co.uk/user-friendly-resources/css/css-forms.shtml

tux
07-18-2013, 10:39 PM
Christie, if you continue to use this form, don't forget to change the form action to contact_submit.php

tux
07-18-2013, 11:24 PM
Just noticed, this can be removed as will not be needed......

function MM_validateForm() { //v4.0
if (document.getElementById){
var i,p,q,nm,test,num,min,max,errors='',args=MM_valida teForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
if (val) { nm=val.name; if ((val=val.value)!="") {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
} else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
} if (errors) alert('The following error(s) occurred:\n'+errors);
document.MM_returnValue = (errors == '');
} }

This looks like it was added by a Dreamweaver Wizard. Don'y use wizards, they add lots of weird code that is not needed. Also, I wont be able to help much if your website is built using them. Learn to code yourself, its not that hard once you get your head around it.

Chrismc
07-18-2013, 11:31 PM
I removed that extra code that is not needed. I will add the code where you suggested. I will also redo the contact form and removed the tables.

You can see the site at
www.lifecoachingbydeano.com

I had posted a question earlier that you must have overlooked. Here it is:

With this string of code:

$fname = $_POST['firstname']; //THIS IS USED WITH THE REDIRECT TO GREET THE USER WITH THEIR NAME

should I use 'clientname' - in my contact form clientname is the ID and the value is Name.
Should I make $fname - $cname ?

tux
07-18-2013, 11:39 PM
Try this Christie.....

<?php

$do = $_GET['do'];
$firstname = $_GET['name'];

if($do == "y"){
$thankyou = "<span class=\"success\">Thank you " . $firstname . ", your message has been sent.</span>";
$error = "";
$fail = "";
$spamfail = "";
}elseif($do == "fail"){
$fail = "Your message wasn't sent ". $firstname .". An error occured, please try again.";
$thankyou = "";
$error = "";
$spamfail = "";
}elseif($do == "n"){
$error = "Your message wasn't sent ". $firstname .". Be sure all fields are complete and try again!";
$thankyou = "";
$fail = "";
$spamfail = "";
}elseif($do == "spamfail"){
$spamfail = "Your message wasn't sent ". $firstname .". Be sure to get your maths correct!";
$thankyou = "";
$fail = "";
$error = "";
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Free Trial - Contact Me</title>
<link href="deansindex.css" rel="stylesheet" type="text/css" />
<style type="text/css">

/* FORMS */

ul, li{
list-style-type:none;
text-decoration: none;
}

.error{
color: #FF0000;
font-weight: bold;
}

.success{
color: #00CC00;
font-weight: bold;
}

</style>
<script type="text/javascript">

</script>
</head>

<body>

<div id="wrap">
<div class="freetrialheaderbox"><img src="Images/freetrialheader.png" width="915" height="200" /></div>



<div class="buttonbox">

<a href="index.html"><div class="homebutton"><img src="Images/homebuttonresized.png" width="73" height="56" /></div></a><!--end homebutton-->

<a href="misson.html"><div class="missionbutton"><img src="Images/missionbuttonresized.png" width="90" height="56" /></div></a><!--end missionbutton-->

<a href="meditation.html"><div class="meditationbuton"><img src="Images/Meditationbuttonresized.png" width="114" height="56" /></div></a><!--end meditationbutton-->

<a href="freetrial.html"><div class="freetrialbutton"><img src="Images/freetrialbuttonresized.png" width="114" height="56" /></div></a><!--end freetrialbutton-->

<a href="rates.html"><div class="ratesbutton"><img src="Images/ratesbuttonresized.png" width="74" height="56" /></div></a><!--end ratesbutton-->

<a href="blog.html"><div class="blogbutton"><img src="Images/blogbuttonresized.png" width="64" height="56" /></div></a><!--end blogbutton-->

<a href="credentials.html"><div class="credentialsbutton"><img src="Images/credentialsbuttonresized.png" width="114" height="56" /></div></a><!--end credentialsbutton-->

<a href="library.html"><div class="librarybutton"><img src="Images/librarybuttonresized.png" width="86" height="56" /></div></a><!--end librarybutton-->

</div><!--end buttonbox-->

<div class="body">

<div class="freetrialparagraphbox"><img src="Images/freetrial.png" width="915" height="225" /></div>
<p><!--end freetrialparagraphbox-->


<div class="freetrialimagebox"></div><!--end freetrialimagebox-->


<strong><strong><center> Fill Out This Free Trial Form:</center></strong><strong>


</p>

<form name="contact" method="post" action="contact_submit.php">
<input type="hidden" name="submitted" id="submitted" value="1" />
<ul>
<li><span class="success"><?php echo $thankyou; ?></span><span class="error"><?php echo $error; ?></span><span class="error"><?php echo $spamfail; ?></span></li>

<li>*Name</li>
<li><input name="clientname" type="text" id="clientname" value=""/></li>
<li>*Email</li>
<li><input name="email" type="text" id="email" value=""/></li>
<li>*Your Message</li>
<li><textarea name="message" type="text" id="message" value="" ></textarea></li>
<li>*To help stop spam do the maths!</li>
<li>5 + 3 = ?</li>
<li><input name="spam_filter" type="text" id="spam_filter" value=""/></li>
<li><input type="submit" name="submit" value="Submit" /></li>

</ul>
</form>
<div class="mycreditmessagefreetrialpage">Designed by: Christie McCormick: cmdesign.co</div><!--end myscreditmessagefreetrialpage-->


</div><!--end body-->
</div><!--end wrap-->


</body>
</html>


I have formatted the form a bit but you can sort that out later to suit. I have changed firstname to clientname. In contact_submit.php you will have to change the variables as needed to match. For example,

$fname = $_POST['firstname'];

needs to be

$fname = $_POST['clientname'];

You will have to go through the script and change all instances of the variables to suit what is coming from the form.

Chrismc
07-18-2013, 11:57 PM
Thank you. That helps.

In this string of code what exactly does it want where it says

$db = mysql_select_db($database, $link);

I put the database name where it said $database, but what about where it says "$link"

does it want the website address to phpmyadmin?

tux
07-19-2013, 12:10 AM
$database = "YOUR DATABASE NAME HERE";//This sets your Database name to the variable $database
$username = "YOUR DATABASE USERNAME HERE";//This sets your database username to the variable $username
$password = "YOUR DATABASE PASSWORD HERE";//This sets your database password to the variable $password
//////////

$link = mysql_connect('localhost', $username, $password);//here the connection is called and set to the variable $link
$db = mysql_select_db($database, $link);/////////now the database name and connection are called using the variables

So all you need to do is set the three variable with your info. Dont change the other two lines. Hope this helps you understand! :)

Chrismc
07-19-2013, 12:14 AM
Yes that did help. I returned the other two lines to how they were originally. thank you. :)

tux
07-19-2013, 12:18 AM
Christie, years ago when I first tried building websites I came across this forum by chance. I knew virtually nothing about Database, Mysql & PHP. There used to be a guy on here called David Jackson. He taught me loads and what I know now is pretty much down to him.

David created lots of tutorials and the first one that set me on my way was his beginners guide. I strongly recommend that you take some time to watch them. It will help you immensely. They are available here on this website here...

http://www.dreamweaverclub.com/vtm/php-mysql-apache.php

Chrismc
07-19-2013, 12:35 AM
I will do that thanks again.

Chrismc
07-19-2013, 12:47 AM
Well I am messing around with css and the form and when i went to preview it, all the code above

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0

showed up above my header that says Free Trial

tux
07-19-2013, 10:10 AM
Did you include the <?php ?> tags?


<?php

//code block here//

?>

<!doctype> etc...

Chrismc
07-19-2013, 04:31 PM
Yes. I copied and pasted what you said to try back on post #50. It had the tags at the beginning and the end.

Also I couldn't get the contact form you offered me to format like I wanted using CSS. I created a different one without a table. When I say created, I found someone else's form and changed it up to the way i need it. For some reason though, when I tried to get the box for name and email to allow more characters they didn't get any larger, but the number I wanted showed up in the code. Is there something I can do? Also, is there a way to get the submit and rest buttons to center on it? Here is the code:<?php echo $thankyou; ?><?php echo $error; ?><?php echo $spamfail; ?>


<div class="formLayout" id="contactform">

<p>
<label> Name:</label>
<input name="clientname" type="text" id="clientname" size="75" maxlength="100" />
<br>
<label>Email:</label>
<input name="email" type="text" id="email" size="75" maxlength"100"/><br>
<label>Comments:</label>
<textarea name="comments" cols="75" rows="3" id="comments"></textarea>
<form id="form1" name="form1" method="post" action="">
<label>
<input name="submit" type="submit" id="submit" onclick="MM_validateForm('clientname','','R','email','','Ri sEmail');return document.MM_returnValue" value="Submit" />
</label>
</form>
<form id="form2" name="form2" method="post" action="">
<label>
<input type="reset" name="reset" id="reset" value="Reset" />
</label>
</form>
<p>
</div><!--end formlayout-->

Also, when I validate the submit button, is when all that spry code shows up at the top. I need for it to validate, to make sure the client fills out the two fields, unless there is another way.

tux
07-19-2013, 05:59 PM
The validation is done in contact_submit,php, you will not need to do any more validation. This form doesn't look right and I don't like the MM_ validation, I think that is done by Dreamweaver and should be avoided. I use DW as a text editor and don't use it to actually build a website.

What I sent you worked perfectly before I sent it to you so it must just be something you have changed.

I am just on my way out for a family evening. I will help you get this sorted in the morning. If you PM me your database and email settings I will write it all up for you as it needs to be. You can then hopefully see it working and then go through the code and figure out how it all works.

Don't worry we will get you sorted with this Christie.

Regards, Paul

Chrismc
07-19-2013, 06:09 PM
Okay, sounds good.

I believe you that it worked fine, the contact form code. The thing is my dad wants his form to look a certain way. He wants the words name, email and comment, right beside the boxes and centered in the middle of the form. That is why I tried using the table in the first place. It made it easy. The form you sent me, while I sure it was fully functioning, wasn't set up that way. I couldn't figure out how to use CSS to change it around.

As for the validation, I will remove that. I only ever learned to create websites in dreamweaver so that is all I know, for now anyway.

Have a good time with your family. We can work more on this tomorrow. Thank you!

tux
07-20-2013, 01:48 PM
Okay Christie, try these files. Replace them with your original files, you should need to retain any of your existing code but back them up first just in case. You will still have to enter your own Database and Email settings in contact_submit.php, but I have had this working fine my end. It assumes that your database tables are 'clientname', 'email' and 'message'. If they are different you will have to alter the code to suit. The form is formatted to look a bit better. You can take a look at the css at the top of the page and figure out for yourself how it effects things and adjust it to suit what you want. You can copy it into your own external style sheet and remove it from this file.

contact.php

<?php

$do = $_GET['do'];
$firstname = $_GET['name'];

if($do == "y"){
$thankyou = "<span class=\"success\">Thank you " . $firstname . ", your message has been sent.</span>";
$error = "";
$fail = "";
$spamfail = "";
}elseif($do == "fail"){
$fail = "Your message wasn't sent ". $firstname .". An error occured, please try again.";
$thankyou = "";
$error = "";
$spamfail = "";
}elseif($do == "n"){
$error = "Your message wasn't sent ". $firstname .". Be sure all fields are complete and try again!";
$thankyou = "";
$fail = "";
$spamfail = "";
}elseif($do == "spamfail"){
$spamfail = "Your message wasn't sent ". $firstname .". Be sure to get your maths correct!";
$thankyou = "";
$fail = "";
$error = "";
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Free Trial - Contact Me</title>
<link href="deansindex.css" rel="stylesheet" type="text/css" />
<style type="text/css">

/* FORMS */
#contact_form_holder{
width: 100%;
}

#contact_form{
width: 400px;
background-color: #999999;
margin: 0 auto 0 auto;
padding: 10px;
border: 1px solid #000000;
}

form{font-size: .9em; font-family: Verdana, Arial, Helvetica, sans-serif;}

.clientname{
width: 400px;
margin: 5px 0 0 0;
text-align: right;
}
.clientname label{
vertical-align: top;
}
.clientname input{
width: 235px;
margin: 0 0 0 15px;
border: 1px solid #000000;
}
.email{
width: 400px;
margin: 5px 0 0 0;
text-align: right;
}
.email label{
vertical-align: top;
}
.email input{
width: 235px;
margin: 0 0 0 15px;
border: 1px solid #000000;
}
.message textarea{
width: 230px;
height: 50px;
margin: 0 0 0 15px;
border: 1px solid #000000;
}
.message{
width: 400px;
margin: 5px 0 0 0;
text-align: right;
}
.message label{
vertical-align: top;
}
.maths{
width: 400px;
margin: 5px 0 0 0;
text-align: right;
}
.mathslabel{
margin: 10px 0 10px 15px;
text-align: left;
}
.maths input{
width: 235px;
margin: 0 0 0 15px;
border: 1px solid #000000;
}
.button{
width: 400px;
margin: 10px 0 10px 0;
text-align: right;
}
.form_button input{
border: 1px solid #000000;
float: right;
}
.error{
color: #FF0000;
font-weight: bold;
margin: 0;
}
.success{
color: #00CC00;
font-weight: bold;
margin: 0;
}
.required{
font-size: .7em;
}
</style>
<script type="text/javascript">

</script>
</head>

<body>

<div id="wrap">
<div class="freetrialheaderbox"><img src="Images/freetrialheader.png" width="915" height="200" /></div>



<div class="buttonbox">

<a href="index.html"><div class="homebutton"><img src="Images/homebuttonresized.png" width="73" height="56" /></div></a><!--end homebutton-->

<a href="misson.html"><div class="missionbutton"><img src="Images/missionbuttonresized.png" width="90" height="56" /></div></a><!--end missionbutton-->

<a href="meditation.html"><div class="meditationbuton"><img src="Images/Meditationbuttonresized.png" width="114" height="56" /></div></a><!--end meditationbutton-->

<a href="freetrial.html"><div class="freetrialbutton"><img src="Images/freetrialbuttonresized.png" width="114" height="56" /></div></a><!--end freetrialbutton-->

<a href="rates.html"><div class="ratesbutton"><img src="Images/ratesbuttonresized.png" width="74" height="56" /></div></a><!--end ratesbutton-->

<a href="blog.html"><div class="blogbutton"><img src="Images/blogbuttonresized.png" width="64" height="56" /></div></a><!--end blogbutton-->

<a href="credentials.html"><div class="credentialsbutton"><img src="Images/credentialsbuttonresized.png" width="114" height="56" /></div></a><!--end credentialsbutton-->

<a href="library.html"><div class="librarybutton"><img src="Images/librarybuttonresized.png" width="86" height="56" /></div></a><!--end librarybutton-->

</div><!--end buttonbox-->

<div class="body">

<div class="freetrialparagraphbox"><img src="Images/freetrial.png" width="915" height="225" /></div>
<p><!--end freetrialparagraphbox-->


<div class="freetrialimagebox"></div><!--end freetrialimagebox-->


<strong><strong><center> Fill Out This Free Trial Form:</center></strong><strong>


</p>

<div id="contact_form_holder">
<div id="contact_form">
<form name="contact" method="post" action="contact_submit.php">
<input type="hidden" name="submitted" id="submitted" value="1" />
<input type="hidden" name="subject" id="subject" value="Email from website contact form" />

<div class="required">* = Required fields</div>

<p><span class="success"><?php echo $thankyou; ?></span><span class="error"><?php echo $error; ?></span><span class="error"><?php echo $spamfail; ?></span></p>

<div class="clientname"><label for="clientname">*Client Name:</label><input name="clientname" type="text" id="clientname" value=""/>
</div>

<div class="email"><label for="email">*Email:</label><input name="email" type="text" id="email" value=""/>
</div>

<div class="message"><label for="message" class="top">*Your Message:</label><textarea name="message" type="text" id="message" value="" ></textarea>
</div>

<div class="mathslabel">To help stop spam please do the maths!</div>

<div class="maths"><label for="spam_filter">*5 + 3 = ?:</label><input name="spam_filter" type="text" id="spam_filter" value=""/>
</div>

<div class="button"><input type="submit" name="submit" value="Submit" /></div>
</form>
</div><!-- end contact_form div -->
</div><!-- end contact_form_holder div -->

<div class="mycreditmessagefreetrialpage">Designed by: Christie McCormick: cmdesign.co</div><!--end myscreditmessagefreetrialpage-->


</div><!--end body-->
</div><!--end wrap-->


</body>
</html>

contact_submit.php

<?php
$database = "YOUR DATABASE NAME HERE";
$username = "YOUR DATABASE USERNAME HERE";
$password = "YOUR DATABASE PASSWORD HERE";
//////////

$link = @mysql_connect('localhost', $username, $password);
$db = mysql_select_db($database, $link);

$fname = $_POST['clientname']; //THIS IS USED WITH THE REDIRECT TO GREET THE USER WITH THEIR NAME

ob_start();

$clientname = $_POST['clientname'];// EDIT THESE VARIABLES TO SUIT
$email = $_POST['email'];
$message = $_POST['message'];//message variable for email
$message_db = $_POST['message'];//message variable for database
$subject = $_POST['subject'];

echo $_POST['clientname'];
echo $email;
echo $message;


if($_POST['spam_filter'] == 8){ // THIS CHECKS THAT THE SPAM QUESTION GETS ANSWERED CORRECTLY

if($clientname && $email && $message && $message_db){ // THIS CHECKS THAT THE REQUIRED FIELDS ARE SET

if(isset($_POST['submit'])) // CHECKS THAT THE FORM HAS BEEN SUBMITTED
{
require("class.phpmailer.php"); // CALLS THIS FILE

$mail = new PHPMailer(); // CALLS THE MAILER FUNCTION

//Your SMTP servers details

$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "localhost"; // specify main and backup server or localhost
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "USERNAME"; // SMTP username
$mail->Password = "PASSWORD"; // SMTP password
//It should be same as that of the SMTP user

$redirect_url = "contact.php?do=y&name=$fname"; //Redirect URL after submit the form
$redirect_url_fail = "contact.php?do=n&name=$fname"; //Redirect URL after fail to submit the form

$mail->From = "EMAIL ADDRESS"; //Default From email same as smtp user
$mail->FromName = "NAME"; //Name

$mail->AddAddress("EMAIL ADDRESS", "NAME"); //Email address where you wish to receive/collect the emails and recipients name.

$mail->WordWrap = 50; // set word wrap to 50 characters
$mail->IsHTML(true); // set email format to HTML

$mail->Subject = $subject;

$message = "Client Name : ".$clientname." \r\n <br>Email Address : ".$email." \r\n <br>Message : ".$message;
$mail->Body = $message;



if(!$mail->Send())
{
header("Location: $redirect_url_fail");
exit;
}

$query = "INSERT INTO users (clientname, email, message) values ('$clientname', '$email', '$message_db')"; // CHANGE TO SUIT YOUR REQUIRED DATABASE ENTRIES
mysql_query($query)or die(mysql_error());
header("Location: $redirect_url");
}

}else
header("Location: contact.php?do=n&name=$fname");
exit;
}else
header("Location: contact.php?do=spamfail&name=$fname");
exit;

?>

Let me know how you get on and if you need any more help.

Chrismc
07-20-2013, 07:01 PM
I will follow your instructions. Thank you. I have two other tables in my Dad's database, but for now only one form that will go there. The other information my dad is getting emailed to him. Should I delete the other two tables for now?
Also, the field in the form called message is only something that will be emailed to my dad, not to the database so I can delete the portion int he contact_submit form where it says,"message db.............." right?

Chrismc
07-20-2013, 07:03 PM
The columns in the table referring to the contact form are Client ID, Clientname and Email.

Chrismc
07-20-2013, 07:10 PM
The class.smtp.php and the class.phpmailer.php should be fine as they are right? The just need to be uploaded. I only have to make adjustments to the contact_submit.php?

Chrismc
07-20-2013, 07:14 PM
Never mind this..message, tried to delete it and i couldn't

Chrismc
07-20-2013, 07:25 PM
On this portion of the code:

$redirect_url = "contact.php?do=y&name=$fname"; //Redirect URL after submit the form
$redirect_url_fail = "contact.php?do=n&name=$fname"; //Redirect URL after fail to submit the form

do I leave it or change "y&name=$fname" to y&clientname=$fname ?

tux
07-20-2013, 07:46 PM
$query = "INSERT INTO users (clientname, email, message) values ('$clientname', '$email', '$message_db')"; // CHANGE TO SUIT YOUR REQUIRED DATABASE ENTRIES

On my iPhone so can't reply as normal but in the above code, users needs to match the name of your database table. Then change client name to Clientname and email to Email. If you don't want the message added to the DB then remove ', message' and ', $message_db'.

You can also remove $message_db = $_POST['message']; at the top.

Hope this is okay as typing it on my iPhone.

tux
07-20-2013, 07:54 PM
You should not have a contact_error.php file? You only need the 4 files. Use the contact.php as I sent it and the contact_submit.php as I sent but with your details and the amendments I said in the last post. The other two files dont need touching. This should then all work fine.

tux
07-20-2013, 07:55 PM
No don't change that at all.

Chrismc
07-20-2013, 08:40 PM
Everything as far as the form looks great. I was able to adjust things as needed. You said with the code you added the form will validate and be sent to my dad's email and to the database as long as the other forms are added to the root folder, correct?

My only issue is the php code showing up at the top of my page when I preview it. Is there somewhere else I should be putting it?

tux
07-20-2013, 08:56 PM
Doesn't have to be the root but the 4 files have to be in the same folder.

What is it exactly that shows up at the top of the page?

Chrismc
07-20-2013, 09:08 PM
Here is what it shows.

tux
07-20-2013, 09:30 PM
Did you use the code I sent you as it was or have you tried to add the code to your own page.

You need to use the two files I sent you earlier. contact.php which you do not need to change and contact_submit.php which you just have to add your details to.

Don't use your old contact.php file, over right it with my code. My contact.php will look the same as yours.

Chrismc
07-20-2013, 09:43 PM
I deleted what was originally on my Free Trial page. I pasted exactly what you sent me in place. I only tweaked the form settings which you said I could do so it looked as I wanted it to. I didn't use the old file.

The contact_submit form I added my own details to, infact I made two versions one with my email and one with my dads, so I can test it using mine.

tux
07-20-2013, 11:54 PM
It looks like this.....

<?php

$do = $_GET['do'];
$firstname = $_GET['name'];

if($do == "y"){
$thankyou = "<span class=\"success\">

.... is missing from the top of your code!

Chrismc
07-21-2013, 12:08 AM
It may be missing when I preview it, but it is all in the dreamweaver file. Here is a screenshot of the page before I preview it.

Chrismc
07-21-2013, 12:09 AM
Message sent twice. Ignore this.

Chrismc
07-21-2013, 12:23 AM
Is there another place to post the php code so that it doesn't show up on the page?

tux
07-21-2013, 07:43 AM
We are working with 'php' and looking at your screenshot and at the live site here www.lifecoachingbydeano.com all your pages are saved as html.

You need to re save all of your files as php files. ( .php and not .html )

tux
07-21-2013, 08:06 AM
Also, if you are going to be using freetrial.php instead of contact.php you will have to change the redirects in contact_submit.php like this....

$redirect_url = "freetrial.php?do=y&name=$fname"; //Redirect URL after submit the form
$redirect_url_fail = "freetrial.php?do=n&name=$fname"; //Redirect URL after fail to submit the form

and this......

else
header("Location: freetrial.php?do=n&name=$fname");
exit;
}else
header("Location: freetrial.php?do=spamfail&name=$fname");
exit;

Chrismc
07-21-2013, 03:05 PM
So I need to resave all my pages as php?

I also have my Dad's site optimized on Google. Do I need to go back and re do that as well since everything will now be php?

Is making everything php going to mess up how it looks?

Do I need to delete all his pages on Godaddy and re upload everything?

tux
07-21-2013, 03:44 PM
Yes, php is a scripting language. The server looks at the php code, processes it and then sends it to the browser with the html to be displayed. It wont effect how the page looks. With an .html affix to your files the server will just process the code as is and ignore the php.

I'm not too up to speed with Search Engine Optimisation (SEO) so not sure if it will make a difference. Google will pick it up eventually but maybe you should at least register the new index.php.

If think you really should watch David Jacksons tutorials before you go any further. It will give you a much better understanding of what you are trying to acheive.

http://www.dreamweaverclub.com/vtm/php-mysql-apache.php

Chrismc
07-21-2013, 05:52 PM
Once I copy and past all the pages code to a new php file can I attach the css to it? Right now my dad is having an issue with getting the mail from free trial sent to him. So I may have to hold off on this database stuff for a bit anyhow. But thank you for your help so far.

Chrismc
07-21-2013, 06:14 PM
For right now can you help me get my Dad's free trial form working? It use to send to him no problem. For some reason now a client will fill it out but it won't send to him. There is a gdform.php on the server in his root folder. In the form it is listed as the action.

Here is the code as of now.

</p>

<table width="100%" border="0" cellpadding="5" bgcolor="#CCCCCC" id="contactform">
<tr>
<td width="20%" height="228"><form action="gdform.php" method="post" enctype="enctype=&quot;text/plain&quot;" name="contactform" id="contactform">
<p align="right">
<label><span class="textinform">
Name:<br />
</span></label>
</p>
<p align="right">
<span class="textinform">
<label>Email:<br />
<br />
</label>
</span></p>
<p align="right">
<span class="textinform">
<label>Comment:</label>
</span></p>
<p align="right"><br />
<br />
</p>
<p align="right"><br />
</p>
</form></td>
<td width="80%"><form id="form2" name="form2" method="post" action="">
<p>
<input name="clientname" type="text" id="clientname" size="45" />
</p>
<p>
<input name="email" type="text" id="email" size="25" />
</p>
<p>
<textarea name="comments" id="comments" cols="75" rows="5"></textarea>
</p>
<p>
<label>
<input name="button" type="submit" id="button" onclick="MM_validateForm('clientname','','R','email','','Ri sEmail');return document.MM_returnValue" value="Submit" />
<input type="reset" name="button2" id="button2" value="Reset" />
</label>
</p>
</form>
<form id="form1" name="form1" method="post" action="">
<input type="hidden" name="hiddenField" id="hiddenField" />
</form></td>
</tr>
</table>

tux
07-21-2013, 06:36 PM
Christie, you have all you need to make this work now. I really don't have time right now to start finding a solution to something else, especially DW created code!

You only need to open your existing files and re save them as .php using 'save as'. No need to copy and paste all the code. It really would be quicker to press on and get it done. As long as you have added your own settings correctly it should all work. I had it working for me before I posted the code so can't understand why you haven't got this up and running.

Chrismc
07-21-2013, 08:50 PM
I understand. I will try all of this out soon. Just want to make sure my dad gets his emails from the contact form he has now first. I appreciate all the time you have put in to helping me out.

tux
07-21-2013, 09:03 PM
You only have to change the page that is using php, not every page. At this point I think you only have the freetrial page to do and it should all work.