View Full Version : Need A Petition Form... I'm Taking A Stand! Please Help!!!!
1980LT-1
05-12-2005, 07:30 AM
Okay, Here is my dilema... I am very new to all of this, and I am slowly developing my skills. I have had a hard time understanding how to setup the email forms using PHP, CGI, etc. My host supports CGI, and I assume it supports PHP because I have a PHPbb on my website. I am looking to set up an e-mail form, which sends simple info to me, ie. first name, last name, e-mail address, and comments. Here is the tricky part, it is for a petition, and I also want this to update the online petition on my website, so I don't manually have to do it for each person. Is this possible? Can someone please walk me through the process slowly and easily on how to do this if it is possible. Your help is appreciated, and I would like to thank you in advance. The site I am now working on is a Shediac, NB tourism site located at MY WEBSITE (http://www.****crabsinshediac.com) or check out the other site I am doing here: Hand'Solo Records (http://www.handsolorecords.com)
Gamini
05-12-2005, 09:02 AM
Its quite simple.
1. You need a place to store the content of the online petition on your site.
E.g. A Mysql database
2. Code the form in pure html and put the action to submit to a php file called something.php
3. Code the php file like this. You can change it as you like.
<?php
//Code to retrive all the variables of the form
$firstname = $_POST['firstname'];
$lastname = $_POST['lastnane'];
//Connect to the mysql database
$db_host = "localhost";
$db_name = "foobar";
$db_user = "user";
$db_pass = "password";
$conn = mysql_connect($db_host, $db_user, $db_pass);
mysql_select_db($db_name) or die ("Could not access db");
//Generate query to update the database
$query = "INSERT INTO `petition` VALUES(`firstname`='$firstname', `lastname`='$lastname')";
//Submit the query and output the success of the query (or failure)
if(mysql_query($query)) {
echo "Query was submitted";
} else {
echo "An error was made";
}
//You can have it send an email to you
mail("foo@bar.com", "Petition Submitted", $lastname ."<br>". $firstname);
?>
1980LT-1
05-12-2005, 09:53 AM
Okay, I see that is the PHP code, is there a basic HTML code I can use with this and alter to my needs?
Can you please explain to me whether this will e-mail the info to me, and will it also update a website page?
Can you explain how I would go about installing this on my site.... step by step. I am very new to PHP and normally learn best by following steps, and then adapting them from there.... I would really appreciate it. Thanks.
1980LT-1
05-12-2005, 09:58 AM
Okay, I have added a mysql database.... what next :rofl:
scoutt
05-12-2005, 09:25 PM
did you make your html form?
also gamini has a little mistake.
//Generate query to update the database
$query = "INSERT INTO `petition` VALUES('','$firstname','$lastname','$email','$comment')";
that is how it should be. you should have 5 columns, an id field, a firstname, a email field and last name field, a comment field.
Gamini
05-13-2005, 04:57 AM
Now, as scoutt said, make your html form. (By the way, thanks for pointing the mysql error out, scoutt).
:thumbup:
Once you have finished making the html form. Enter the fields into the database
Enter an id field, called id, firstname and so on.
Then once you have done that, you have to write the page which will retrive the data, you can do something like this
<?php
//Connect to the mysql database
$db_host = "localhost";
$db_name = "foobar";
$db_user = "user";
$db_pass = "password";
//Generate query to retrieve the data
$query = "SELECT * FROM `petition`";
$result = mysql_query($query);
?>
<!-- I'm just using rough html, you must add the doctype and make it compliant --!>
<html>
<head>
</head>
<body>
<table>
<tr><td>Id</td><td>Firstname</td><td>Lastname</td><td>Email</td><td>Comment</td></tr>
<?php
//A loop to echo out all the data
while($row = mysql_fetch_array($result)) {
echo "<tr><td>". $row['id'] ."</td><td>". $row['firstname'] ."</td><td>". $row['lastname'] ."</td><td>". $row['email'] ."</td><td>". $row['comment'] ."</td><tr>";
}
?>
</table>
</body>
</html>
1980LT-1
05-14-2005, 05:09 PM
Okay, I have made my HTML form, it has a field for last name, first name, email, and comments. What next? Thanks for all the help.... how do I get it to input the data into mysql, and how does it know which html fields get inputted where in mysql table..... Do you want the code for the table? Would that help?
scoutt
05-14-2005, 05:12 PM
the code you need to insert it into mysql is the second post in this thread.
1980LT-1
05-16-2005, 10:18 AM
Okay, I have setup the mysql through DreamHost, and I am not sure how to get this working. I have the HTML code for the petition, and the PHP code provided above, however I am unsure the code that needs to be changed in order to make it work with mysql. The name of the databse I am using is crabbypetition, my user name is Crabby Johnson, and I'll say the password is Crabby. What other info needs to be changed on this code, and will I end up just having the one file? Any more help would be great Scoutt or anyone else, I am not sure why I am having such a hard time understanding this, it normally all comes so easy. I assume that the PHP requests the data from mysql and then it is shown or echoed onto the actual html shown in your browser. Is this correct?
scoutt
05-16-2005, 10:59 AM
is your site on the same server as mysql?
vBulletin® v3.6.7, Copyright ©2000-2010, Jelsoft Enterprises Ltd.