Whats a code for creating a petition kind of thing where people add there names to it. Im assuming it will be php and i preferably dont want to dl anything. Thanks.
Whats a code for creating a petition kind of thing where people add there names to it. Im assuming it will be php and i preferably dont want to dl anything. Thanks.
You'd need a mysql database and a few statments.
to add a name to the list.
To View the pertitionCode:<?php $con = mysql_connect("localhost","DATABASE USERNAME","DATABASE PASS"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("DATABASE NAME", $con); mysql_query("INSERT INTO pertition (FirstName, LastName) VALUES ('$firstname', '$lastname')") or die ("Could not insert"); echo "Thank you, Your name has been added to the pertition"; echo "<form method='post' action='$PHP_SELF?action=add'> <table border=\"0\" cellpadding=\"2\" cellspacing=\"5\"> <tr><td><font face=\"Verdana\" size=\"1\"><b>First Name:</b></td><td><font face=\"Verdana\" size=\"1\"><input type=\"text\" name=\"firstname\" size=\"20\"></td></tr> <tr><td><font face=\"Verdana\" size=\"1\"><b>Last Name:</b></td><td><font face=\"Verdana\" size=\"1\"><input type=\"text\" name=\"lastname\" size=\"20\"></td></tr> <tr><td></td><td><input type='submit' name='submit' value='Apply!'></td></tr> </form>"; ?>
Code:<?php // Make a MySQL Connection mysql_connect("localhost", "DATABASE USERNAME", "DATABASE PASS") or die(mysql_error()); mysql_select_db("DATABASE NAME") or die(mysql_error()); // Get all the data from the "example" table $result = mysql_query("SELECT * FROM pertition") or die(mysql_error()); echo "<table border='1'>"; echo "<tr> <th>First Name</th> <th>Last Name</th> </tr>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row['firstname']; echo "</td><td>"; echo $row['lastname']; echo "</td></tr>"; } echo "</table>"; ?>
Thanks! :eusa_danc +rep
o.0 from what i can tell the mysql table structure to go with that is a table name
'pertition' containing two rows "FirstName" and "LastName" (most likly varchar 255, or possibly text, although that would be a bit of a waste in this instance), although for a vertual petition to hold weight you do also need to record the ip, and a comments also nice.
Plus unless someone injecting some code in to the mysql is a plan, some validation of the inputs, how ever tiny, probably wouldnt go amiss "/
grrrr it isnt working
Try
Add.php
Code:<?php $con = mysql_connect("localhost","DATABASE USERNAME","DATABASE PASS"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("DATABASE NAME", $con); if($action == "add") { $add = mysql_query("INSERT INTO `pertition` ( `firstname`, `lastname`) VALUES ('$firstname', '$lastname')"); echo "Your name has been added to the pertition"; } else { echo "<form method='post' action='$PHP_SELF?action=add'> <table border=\"0\" cellpadding=\"2\" cellspacing=\"5\"> <tr><td><font face=\"Verdana\" size=\"1\"><b>First Name:</b></td><td><font face=\"Verdana\" size=\"1\"><input type=\"text\" name=\"firstname\" size=\"20\"></td></tr> <tr><td><font face=\"Verdana\" size=\"1\"><b>Last Name:</b></td><td><font face=\"Verdana\" size=\"1\"><input type=\"text\" name=\"lastname\" size=\"20\"></td></tr> <tr><td></td><td><input type='submit' name='submit' value='Apply!'></td></tr> </form>"; } ?>
View.php
MySQLCode:<?php // Make a MySQL Connection mysql_connect("localhost", "DATABASE USERNAME, "DATABASE PASS") or die(mysql_error()); mysql_select_db("DATABASE NAME) or die(mysql_error()); // Get all the data from the "example" table $result = mysql_query("SELECT * FROM pertition") or die(mysql_error()); echo "<table border='1'>"; echo "<tr> <th>First Name</th> <th>Last Name</th> </tr>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row['firstname']; echo "</td><td>"; echo $row['lastname']; echo "</td></tr>"; } echo "</table>"; ?>
Code:-- -- Table structure for table `pertition` -- CREATE TABLE `pertition` ( `id` int(11) NOT NULL auto_increment, `firstname` varchar(50) NOT NULL default '', `lastname` varchar(50) NOT NULL default '', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ; -- -- Dumping data for table `pertition` --
Members who have read this thread: 0Want to hide these adverts? Register an account for free!