Okay here goes I have 3 separate php files to handle modifying, adding, and Displaying.
first file is: wod_admin.php
[php]<?php
include ‘core/init.php’;
protect_page();
include ‘includes/overall/overallheader.php’;
include(‘connection.php’);
?>
<?php include 'includes/admin_menu.php'; ?>
<?php
include('connection.php');
$query="SELECT * FROM `wod` ORDER BY `id` DESC";
$resource=mysql_query($query);
?>
Add New WOD
Current WOD List
Month |
Day |
Year |
Name |
<?php
while($result=mysql_fetch_array($resource))
{
echo "
".$result['month']." |
".$result['day']." |
".$result['year']." |
".$result['name']." |
|
";
}
?>
<?php echo $_html; ?>
<?php include 'includes/overall/overallfooter.php'; ?>[/php]
second file is: wod_insert.php
[php]<?php
include ‘core/init.php’;
protect_page();
header(“Location: wod_admin.php”);
$_month = mysql_real_escape_string($_POST['month']);
$_day = mysql_real_escape_string($_POST['day']);
$_year = mysql_real_escape_string($_POST['year']);
$_name = mysql_real_escape_string($_POST['name']);
$_w1 = mysql_real_escape_string($_POST['w1']);
$_w2 = mysql_real_escape_string($_POST['w2']);
$_w3 = mysql_real_escape_string($_POST['w3']);
$_w4 = mysql_real_escape_string($_POST['w4']);
$_w5 = mysql_real_escape_string($_POST['w5']);
$_w6 = mysql_real_escape_string($_POST['w6']);
$_imagelocation = mysql_real_escape_string($_POST['$imagelocation']);
$_comment = mysql_real_escape_string($_POST['comment']);
$sql="INSERT INTO `wod` SET `month`='$_month',
`day`='$_day',
`year`='$_year',
`name`='$_name',
`w1`='$_w1',
`w2`='$_w2',
`w3`='$_w3',
`w4`='$_w4',
`w5`='$_w5',
`w6`='$_w6',
`imagelocation`='$_imagelocation',
`comment`='$_comment'
";
if (!mysql_query($sql))
{
die('Error: ' . mysql_error());
}
mysql_close($con);
?> [/php]
third file is wod_modify.php
[php]<?php
include ‘core/init.php’;
protect_page();
include ‘includes/overall/overallheader.php’;
include(‘connection.php’);
?>
<?php include 'includes/admin_menu.php'; ?>
<?php
function GetFileName($f)
{
$h=substr($f,strrpos($f,"/"),strrpos($f,"."));
$FileName= substr($h,1,strrpos($h,".")-1);
return $FileName;
}
$_id = (int)($_GET['id']);
$_sql ="SELECT * FROM `wod` WHERE `id`=$_id LIMIT 5";
$_rs = mysql_query($_sql);
while($_rw = mysql_fetch_assoc($_rs))
{
$_id = $_rw['id'];
$_month = $_rw['month'];
$_day = $_rw['day'];
$_year = $_rw['year'];
$_name = $_rw['name'];
$_comment = $_rw['comment'];
$_imagelocation = $_rw['imagelocation'];
}
?>
<?PHP
if(isset($_POST['edit']))
{
$_month = mysql_real_escape_string($_POST['_month']);
$_day = mysql_real_escape_string($_POST['_day']);
$_year = mysql_real_escape_string($_POST['_year']);
$_name = mysql_real_escape_string($_POST['_name']);
$_comment = mysql_real_escape_string($_POST['_comment']);
$_id = (int)$_POST['id'];
$image_location = $_POST['_imagelocation'];
if(is_uploaded_file($_FILES['myfile']['tmp_name']))
{
$name = $_FILES['myfile']['name'];
$tmp_name = $_FILES['myfile']['tmp_name'];
$location = "../../../images/wod/$name";
move_uploaded_file($tmp_name,$location);
}
$_SQL = "UPDATE `wod` SET `month`='$_month',
`day`='$_day',
`year`='$_year',
`name`='$_name',
`comment`='$_comment',
`imagelocation`='$location'
WHERE `id`='$_id'";
mysql_query($_SQL) or die(mysql_error());
//header("Location : index.php?id=$_id");
$_html ="
RECORD HAS BEEN |
UPDATED CLICK HERE
|
";
}
elseif(isset($_POST['delete']))
{
$id = (int)$_POST['id'];
mysql_query("DELETE FROM `wod` WHERE `id`='$id' LIMIT 1");
$_html = 'Record deleted successfully!
Return to "WOD Admin Page" page.';
if ("default" != GetFileName($_POST['_front'])){
unlink($_POST['_front']);
}
}
else
{
$_html="
Image:
|
";
}
?>
<?php echo $_html; ?>
<?php include 'includes/overall/overallfooter.php'; ?>[/php]
I know there is probly a way to code this better, but I am still getting used to PHP/MySQL again. Thank you for your help so far sir.