Ok so I created you an example input form and a page to process the form to MySQL. Copy the codes below and make a separate page with the correct page name for each page and upload them all to the same folder and you will have a working input page and and output page from your MySQL database. These are just examples not meant for production!
This is your first page call it insert.html
[code]
Untitled 2
.auto-style1 {
text-align: right;
}
.auto-style2 {
text-align: center;
}
.auto-style3 {
font-family: "Rosewood Std Regular";
font-size: xx-large;
}
Chapter Membership Input Form
Insert Data Into mySQL Database |
Chapter Number |
: |
|
Chapter Name |
: |
|
Church Name |
: |
|
City |
: |
|
State |
: |
|
|
|
[/code]
This is the second page. Call it insert_ac.php
[php]
Untitled 2
<?php
$host=“daughtershcorg.ipagemysql.com”; // Host name
$username=“daughtershc”; // Mysql username
$password=“holyCross2009$”; // Mysql password
$db_name=“membership”; // Database name
$tbl_name=“Chapters”; // Table name
// Connect to server and select database.
mysql_connect("$host", “$username”, “$password”)or die(“cannot connect”);
mysql_select_db("$db_name")or die(“cannot select DB”);
// Get values from form
$ChapterNumber=$_POST[‘ChapterNumber’];
$ChapterName=$_POST[‘ChapterName’];
$ChurchName=$_POST[‘ChurchName’];
$City=$_POST[‘City’];
$State=$_POST[‘State’];
// Insert data into mysql
$sql=“INSERT INTO $tbl_name(ChapterNumber, ChapterName, ChurchName, City, State)VALUES(’$ChapterNumber’, ‘$ChapterName’, ‘$ChurchName’, ‘$City’, ‘$State’)”;
$result=mysql_query($sql);
// if successfully insert data into database, displays message “Successful”.
if($result){
echo “Successful”;
echo “
”;
// make sure you keep insert_ac.php and insert.html in the same folder if not
// then you will need to change the link below to the correct path of your insert.html file
echo “Back to main page”;
}
else {
echo “ERROR”;
}
?>
<?php
// close connection
mysql_close();
?>
[/php]
This is your 3rd page. Call it Chapter_output.php
[php]
Untitled 2
<?php
// Make your coding easier and create a db connect script and place it in an includes folder
// and just add the following line to all your php scripts that require database connection
//make the connection
$DB_Server = “daughtershcorg.ipagemysql.com”; //MySQL Server
$DB_Username = “daughtershc”; //MySQL Username
$DB_Password = “holyCross2009$”; //MySQL Password
$DB_DBName = “membership”; //MySQL Database Name
$DB_TBLName = “Chapters”; //MySQL Table Name
//create MySQL connection
$sql = “Select * from $DB_TBLName”;
$Connect = @mysql_connect($DB_Server, $DB_Username, $DB_Password)
or die(“Could not connect to MySQL:
” . mysql_error() . “
” . mysql_errno());
//select database
$Db = @mysql_select_db($DB_DBName, $Connect)
or die(“Couldn’t select database:
” . mysql_error(). “
” . mysql_errno());
//execute query
$result = mysql_query($sql)
or die(“Couldn’t execute query:
” . mysql_error(). “
” . mysql_errno());
// This is where you select your table in your database you are already connected to.
$sql = “SELECT * FROM chapters”;
$result = mysql_query($sql)or die(mysql_error());
while($row = mysql_fetch_array($result)){
// Before we close out of PHP, lets define all of our variables so they are easier to remember and work with,
// you can skip this though if you just want to directly reference each row.
$chapternumber= $row[‘ChapterNumber’];
$chaptername= $row[‘ChapterName’];
$churchname = $row[‘ChurchName’];
$city = $row[‘City’];
$state= $row[‘State’];
}
?>
DATABASE OUTPUT
<tr><th class="auto-style2">Chapter Number<div style="width: 122px"><?php echo "$chapternumber" ?>
</div>
</th><th class="auto-style2">Chapter Name<div style="width: 177px"><?php echo "$chaptername" ?>
</div>
</th><th class="auto-style2">Church Name<div style="width: 193px"><?php echo "$churchname" ?>
</div>
</th><th class="auto-style2">City<div style="width: 199px"><?php echo "$city" ?>
</div>
</th><th class="auto-style2">State<div style="width: 232px"><?php echo "$state" ?>
</div>
</th></tr>
[/php]