PDA

View Full Version : Trying to capture form info on database



Rob
03-29-2006, 10:34 AM
Hi All,

I have a form on our contact page. This presently sends the message to us as an email using a php script . We would like to capture this information on a database automatically. I have watched the tutorials on how to set up and manage a database through the control panel but am still confused as to what we actually need to do make the information that is put into the form arrive as an email and go to a data base. Do we need to change or add anything to the php scrip or if we don't how does it end up in the right place.

I am sure it is not as confusing as I am making it !.

Rob

www.saulfarm.com (http://www.saulfarm.com)

navaldesign
03-29-2006, 11:15 AM
Yes, you can write info in your database directly from the php script. You need to have a part of the script specifically writen to accompish this. Also, if you use Pablo's script, it will only be able to define and wite the email to the database. If you need more fields, the sctipt has to be modified.

Rob
03-29-2006, 11:26 AM
Hi Navaldesign,

Thanks for your help.

Is it best to write info in your database directly from the php script or would you recomend another way of doing it as changing the script so it achieves the capture of all the info' sounds pretty complicated !

thanks,

Rob

www.saulfarm.com (http://www.saulfarm.com)

navaldesign
03-29-2006, 02:05 PM
[Well, there is always the manual way of doing it. If you do have a database management inteface script (which i suppose you do have, otherwise what would you do of a database?) then you can update it manually. However, i do have a database writing script. If you want we may try it. And no, it doesn't seem so complicated. I have never tried it though. I will need the name of the database, the name of the table, and username / password of the database. I will also need the URL of the form. Make sure your form is in it's final version

Rob
03-29-2006, 03:43 PM
Hi Navel D,

Should I set up a new database in the control panel and give it name. UN and PW should be part of this process I think ? Not sure about the 'table' ? and is the URL of the form the contact page on the website containing the form or the php page containing the script.

Sorry to be obtuse, but you can see why I'm finding it complicated.

Thanks for bearing with me.

Rob

navaldesign
03-29-2006, 05:19 PM
Hi Navel D,

Should I set up a new database in the control panel and give it name. UN and PW should be part of this process I think ? Not sure about the 'table' ? and is the URL of the form the contact page on the website containing the form or the php page containing the script.

Sorry to be obtuse, but you can see why I'm finding it complicated.

Thanks for bearing with me.

Rob

1. Yes, you must set up a new database.
2. Username and password will be defined during the setup process. 3. Databases have tables where you write the data. Every table has fields.

F.e. a client database may have one table for client info, one table for client's posts, one table for client's purchses (or licenses) etc.
Every table has more fields f.e. the client info table has fields for Address, Tel, Cel, Fax, and so on.
4. I need the form Url to see your fields.

Question, if i am allowed: i can see that you are just starting to learn something about MySQL. Even if i give you a script to handle data uploading in the database, what are you going to do with it? you need a php interface script to handle the database info. Also to be able to manually update, modify, download etc. Then this script must have the ability to create html pages fpr the presentation of the results. Also, you must be able to create and handle querries, otherwise the database will be of no use at all. Are you sure you can handle this? This is more than a complex project, and when i do it, i get paid well for it. Do you feel like facing this kind of job?

Rob
03-29-2006, 11:20 PM
Hi Naveldesign,

Name of database: saul contact form
UN: richard
PW: bookers

Name of table: saul

form is at: http://www.saulfarm.com/contact.html

Th4e information we would like to capture is on the form at the above page. There are 7 fields.

Thanks

Rob

navaldesign
03-30-2006, 05:30 AM
here is your script:

<?php

// Receiving variables
@$Title = addslashes($_POST['Title']);
@$First_Name = addslashes($_POST['First_Name']);
@$Suname = addslashes($_POST['Suname']);
@$Tel_No = addslashes($_POST['Tel_No']);
@$Email = addslashes($_POST['Email']);
@$Subject = addslashes($_POST['Subject']);
@$Message = addslashes($_POST['Message']);

//Sending Email to form owner
$pfw_header = "From: $Email\n"
. "Reply-To: $Email\n";
$pfw_subject = "Put your Subject here";
$pfw_email_to = "youremail@yourvodahostdomain.com ";
$pfw_message = "Info Submitted from Contact Webform\n"
. "----------------------------------------------\n"
. "\n"
. "Title: $Title\n"
. "First_Name: $First_Name\n"
. "Suname: $Suname\n"
. "Tel_No: $Tel_No\n"
. "Email: $Email\n"
. "Subject: $Subject\n"
. "Message: $Message\n";
*****($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;
//saving record to MySQL database

@$pfw_strQuery = "INSERT INTO `saul`(`titlefieldname`,`firstnamefieldname`,`surn amefieldname`,`telfieldname`,`emailfieldname`,`sub jectfieldname`,`messagefieldname`)VALUES (\"$Title\",\"$First_Name\",\"$Suname\",\"$Tel_No\",\"$Email\",\"$Subject\",\"$Message\")" ;
@$pfw_host = "localhost";
@$pfw_user = "richard";
@$pfw_pw = "bookers";
@$pfw_db = "saul_contact_form";
$pfw_link = mysql_connect($pfw_host, $pfw_user, $pfw_pw);
if (!$pfw_link) {
die('Could not connect: ' . mysql_error());
}
$pfw_db_selected = mysql_select_db($pfw_db, $pfw_link);
if (!$pfw_db_selected) {
die ('Can not use $pfw_db : ' . mysql_error());
}
//insert new record
$pfw_result = mysql_query($pfw_strQuery);
if (!$pfw_result) {
die('Invalid query: ' . mysql_error());
}
mysql_close($pfw_link);
header("Location: thankyou_page.html");
?>


Please change the subject and email in the script. Also change the "titlefiledname", "firstnamefieldname" etc. to be the real manes of your fields.

Create a simple html page in BV, name it "thankyou_page" save it and publish it. This will be the page where they will get redirected to after submission.

Copy/paste the script in notepad (or in your favorite php editor if you have one). Modify iy as instructed above. Save it as "contact.php". If you use notepad, to accomplish this you must go in "Save as", the choose File tyoe: "All files", and type in as name: "contact.php". Upload the saved file on your site.
Make sure the "action" of your form is "contact.php" and the encoding "multipart/ form data".

Please also note that the name of your database has probably automaticaly been changed in "saul_contact_form" with underscores. Verify this, as i have asumed it is so, but i can't be certain. Enter your CP, go in MySQL databases, and check the name of your database in your CP.

Rob
03-30-2006, 07:39 AM
Hi Naveldesign,

Received your message sent through the form to our email

The php script we are using is:

<HEAD>
<TITLE>Succesfully processed your Report</TITLE>
</HEAD>
<BODY>
<H2>Thank you for your enquiry!</H2>
<?PHP
$email = $HTTP_POST_VARS[email];
$mailto = "rob@saulfarm.com";
$mailsubj = "Saul contact form";
$mailhead = "From: $email\n";
reset ($HTTP_POST_VARS);
$mailbody = "Values submitted from web site form:\n";
while (list ($key, $val) = each ($HTTP_POST_VARS))
{
$mailbody .= "$key : $val\n";
}
mail($mailto, $mailsubj, $mailbody, $mailhead);
?>
</BODY>
</HTML>

Should I replace this script with the one you have just sent.

Regards

Rob

www.saulfarm.com (http://www.saulfarm.com)

navaldesign
03-30-2006, 10:54 AM
Yes, you must replace it after the changes. Please keep a backup of your original script, just in case.
Please tell me: you did receive the email address of your visitors, but i think you received it as info sent, not in the FROM of the email, correct?
Because in your form the field is Email whilst in the script it is email ( Lowercase E)

Rob
03-30-2006, 12:57 PM
Hi Naveldesign,

For some reason although the database is set up I can't get to set up the table. I have named the table and put 7 in the box for number of fields and at the top of the page it shows its added a table. When you click on the table to edit it it goes back to the original page.

I've not changed the script as I thought best not until confident database is configured properly.

We received the message you sent as from our form straight to our outlook inbox as follows:

Values submitted from web site form:
Submit : Submit
Title : Mr
First_Name : Giorgio
Suname : Navaldesign
Tel_No : 9999999
Email : xxxxxxxx@navaldesign.info
Subject : Bed and breakfast
Message : Please let me know if you have received this. I need to have also the contact.php script that you are using

Thanks,

Rob

navaldesign
03-30-2006, 02:44 PM
Yes, i know you did receive the visitor's email in the message body. What i was asking is if you received it also in the "From" tag, or the from tag was emtpy.

To edit the table field names, go to phpMyAdmin. You will find the link at the bottom of the MySQL Databases page in your CP

Rob
03-30-2006, 08:09 PM
Hi,

The from tag was empty.


Have now been able to open the tabbe to enter the fields. I put in all 7 fields. The other boxes on the table are:

Type length/values Collation Attributes Null Default** Extra

I didn't know what to put in these so I just clicked save at the bottom and a box opened asking to enter a number, I think for Lenght/values ?

I feel I'm getting closer, but not quite there yet I'm afraid.

Thanks

Rob

www.saulfarm.com (http://www.saulfarm.com)

navaldesign
03-30-2006, 08:29 PM
Enter the desired lenght for the fields.

Rob
03-31-2006, 08:44 AM
Based on the 7 field types

Title
First name
Surname
Tel number
Email
Subject
Message

What should the field lengths be ?

Rob

www.saulfarm.com (http://www.saulfarm.com)

navaldesign
03-31-2006, 10:23 AM
DEPENDS ENTIRELY ON YOU. i SUGGEST:


Title 4 (BASED ON WHAT YOU HAVE NOW IN YOUR FORM)
First name 20
Surname 30
Tel number 16
Email 30
Subject 25
Message 255 (MAX)

Rob
04-06-2006, 03:20 PM
Hi Naveldesign,

Sorry I was away for a couple of days so am now back.

Have filled in fields with numbers as suggested and been through the rest of the changes and uploaded.

The name of the database on the CP was "jioioipz_saul" so I changed it where is said "saul_contact_form" on the script.

Have just done a test on the form as I thought all finished and I got the error message:

Parse error: parse error, unexpected ',' in /home/jioioipz/public_html/contact.php on line 30



please can you advise. I feel we are nearly there.

Many thanks,

Rob

www.saulfarm.com (http://www.saulfarm.com)

Rob
04-06-2006, 03:31 PM
Hi,

Have just published up the script again and got the same message only ending with " line 39"

On the script where it says "suname" several time throughout should that be "surname"

thanks,

Rob

www.saulfarm.com (http://www.saulfarm.com)

Rob
04-06-2006, 05:08 PM
If it helps at all the script you suggested is now:

<?php
// Receiving variables
@$Title = addslashes($_POST['Title']);
@$First_Name = addslashes($_POST['First_Name']);
@$Suname = addslashes($_POST['Suname']);
@$Tel_No = addslashes($_POST['Tel_No']);
@$Email = addslashes($_POST['Email']);
@$Subject = addslashes($_POST['Subject']);
@$Message = addslashes($_POST['Message']);
//Sending Email to form owner
$pfw_header = "From: $Email\n"
. "Reply-To: $Email\n";
$pfw_subject = "Saul contact form";
$pfw_email_to = "rob@saulfarm.com ";
$pfw_message = "Info Submitted from Contact Webform\n"
. "----------------------------------------------\n"
. "\n"
. "Title: $Title\n"
. "First_Name: $First_Name\n"
. "Suname: $Suname\n"
. "Tel_No: $Tel_No\n"
. "Email: $Email\n"
. "Subject: $Subject\n"
. "Message: $Message\n";
*****($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;
//saving record to MySQL database
@$pfw_strQuery = "INSERT INTO `saul`(`Title`,`Firstname`,`Surname`,`Telnumber`,` Email`,`Subject`,`Message`)VALUES (\"$Title\",\"$First_Name\",\"$Suname\",\"$Tel_No\ ",\"$Email\",\"$Subject\",\"$Message\")" ;
@$pfw_host = "localhost";
@$pfw_user = "richard";
@$pfw_pw = "bookers";
@$pfw_db = "jioioipz_saul";
$pfw_link = mysql_connect($pfw_host, $pfw_user, $pfw_pw);
if (!$pfw_link) {
die('Could not connect: ' . mysql_error());
}
$pfw_db_selected = mysql_select_db($pfw_db, $pfw_link);
if (!$pfw_db_selected) {
die ('Can not use $pfw_db : ' . mysql_error());
}
//insert new record
$pfw_result = mysql_query($pfw_strQuery);
if (!$pfw_result) {
die('Invalid query: ' . mysql_error());
}
mysql_close($pfw_link);
header("Location: thankyou_page.html");
?>

This may give a clue regarding the error message and why its not working,

Regards,

Rob

Rob
04-06-2006, 09:54 PM
Hi Naveldesign,

I've changed the form back temporarily as we are missing enquiries leaving it not working. I took your advise and have changed the "e" to an "E" on Email script and it is bringing people's mails in on their name rather than from the form as unspecified.

If you can see what I'm doing wrong with the database I'd be really grateful to sort it out as we can then apply the same principles to other sites we have started work on.

Regards,

Rob.


www.saulfarm.com (http://www.saulfarm.com)

navaldesign
04-11-2006, 05:36 PM
Please try again with this. If it still gets an error post back.

<?php
// Receiving variables
@$Title = addslashes($_POST['Title']);
@$First_Name = addslashes($_POST['First_Name']);
@$Suname = addslashes($_POST['Suname']);
@$Tel_No = addslashes($_POST['Tel_No']);
@$Email = addslashes($_POST['Email']);
@$Subject = addslashes($_POST['Subject']);
@$Message = addslashes($_POST['Message']);
//Sending Email to form owner
$pfw_header = "From: $Email\n"
. "Reply-To: $Email\n";
$pfw_subject = "Saul contact form";
$pfw_email_to = "rob@saulfarm.com ";
$pfw_message = "Info Submitted from Contact Webform\n"
. "----------------------------------------------\n"
. "\n"
. "Title: $Title\n"
. "First_Name: $First_Name\n"
. "Suname: $Suname\n"
. "Tel_No: $Tel_No\n"
. "Email: $Email\n"
. "Subject: $Subject\n"
. "Message: $Message\n";
*****($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;
//saving record to MySQL database
@$pfw_strQuery = "INSERT INTO `saul`(`Title`,`Firstname`,`Surname`,`Telnumber`,` Email`,`Subject`,`Message`)VALUES (\"$Title\",\"$First_Name\",\"$Suname\",\"$Tel_No\ ",\"$Email\",\"$Subject\",\"$Message\")" ;
@$pfw_host = "localhost";
@$pfw_user = "richard";
@$pfw_pw = "bookers";
@$pfw_db = "jioioipz_saul";
$pfw_link = mysql_connect($pfw_host, $pfw_user, $pfw_pw);
if (!$pfw_link)
{
die('Could not connect: ' . mysql_error());
}
$pfw_db_selected = mysql_select_db($pfw_db, $pfw_link);
if (!$pfw_db_selected)
{
die ('Can not use $pfw_db : ' . mysql_error());
}
//insert new record
$pfw_result = mysql_query($pfw_strQuery);
if (!$pfw_result)
{
die('Invalid query: ' . mysql_error());
}
mysql_close($pfw_link);
header("Location: thankyou_page.html");
?>

Rob
04-12-2006, 12:01 PM
Hi Naveldesign,

Afraid still gets error, only this time is as follows:

Parse error: parse error, unexpected ',' in /home/jioioipz/public_html/contact.php on line 36

regards,

Rob