Functions.php
<?php
include("../db_connection/db_config.php");
if(isset($_POST["add"]))
{
header("location:../add.php");
}
if(isset($_POST['submit']))
{
$news_title=$_POST['news_title'];
$news_desc=$_POST['news_desc'];
$news_sdate=$_POST['news_sdate'];
$news_edate=$_POST['news_edate'];
$news_status=$_POST['news_status'];
if ($_FILES["file"]["size"] == 0)
{
$fileName="";
}
else
{
if (($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Stored in: " . $_FILES["file"]["tmp_name"];
if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
$fileName= $_FILES["file"]["name"];
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
$fileName= $_FILES["file"]["name"];
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
}
mysql_query("INSERT INTO news (news_title, news_desc, news_sdate, news_edate, status, image)
VALUES ('$news_title', '$news_desc', '$news_sdate', '$news_edate', '$news_status', '$fileName' )");
if(mysql_query)
{
//header("location:../news.php");
}
}
if(isset($_POST['update']))
{
$news_title=$_POST['news_title'];
$news_desc=$_POST['news_desc'];
$news_sdate=$_POST['news_sdate'];
$news_edate=$_POST['news_edate'];
$news_status=$_POST['news_status'];
if ($_FILES["file"]["size"]==0)
{
$result= "UPDATE news SET news_title='$news_title',news_desc='$news_desc', news_sdate='$news_sdate', news_edate='$news_edate', status='$news_status'
WHERE news_id=".$_POST['newsid'];
mysql_query($result);
if(mysql_query)
{
header("location:../news.php");
}
}
else
{
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 90000))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Stored in: " . $_FILES["file"]["tmp_name"];
if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
$fileName= $_FILES["file"]["name"];
//unlink("upload/" . $_FILES["file"]["name"]));
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
$fileName= $_FILES["file"]["name"];
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
$result= "UPDATE news SET news_title='$news_title',news_desc='$news_desc', news_sdate='$news_sdate', news_edate='$news_edate', status='$news_status',image='$fileName'
WHERE news_id=".$_POST['newsid'];
mysql_query($result);
if(mysql_query)
{
header("location:../news.php");
}
}
}
if(isset($_POST['delete']))
{
$news_id=$_POST['delchk'];
foreach ($news_id as $value)
{
$result="DELETE FROM news WHERE news_id =".$value;
//echo $result ."</br>";
mysql_query($result);
}
header("location:../news.php");
}
if(isset($_POST['display']))
{
echo "display"."</br>";;
$newsid=$_POST['newsid'];
foreach ($newsid as $value)
{
$result="UPDATE news SET status=0 WHERE news_id=".$value;
mysql_query($result);
// echo $result ."</br>";
}
echo "updated"."</br>";;
$news_id=$_POST['dischk'];
foreach ($news_id as $value)
{
$result="UPDATE news SET status=1 WHERE news_id=".$value;
mysql_query($result);
//echo $result ."</br>";
}
header("location:../news.php");
}
?>
I think that thanks for the valuabe information and insights you have so provided here. camping mit kind und hund
ReplyDelete