Subject: Hi, please help me with my php codes
I cannot upload my file that is sent by another page. here is my code:
/** * @author alireza
require_once ('database.php');$sender_page='../news.php';if($_GET['t']=="delete") { if(!isset($_GET['id'])) exit('<meta http-equiv="refresh" content="0;url='.$sender_page.'">'); if(!is_numeric($_GET['id'])) exit('<meta http-equiv="refresh" content="0;url='.$sender_page.'">');
$sql_update="DELETE FROM `tbl_news` WHERE `id`='".$_GET['id']."'"; $result_update=$connect->prepare($sql_update); $result_update->execute(); security::Redirect("../news_list");}//---------- insert and update$filename=$_FILES['file']['name'];$file = md5($filename.microtime()).substr($filename,-5,5);move_uploaded_file($_FILES['file']['tmp_name'],"./news/".$file);
$arr = array(':title' => $_POST['title'], ':writer' =>$_POST['writer'], ':shortdesc' =>$_POST['shortdesc'], ':longdesc' =>$_POST['longdesc'], ':date' =>$_POST['date'], ':img' =>$file );if($_GET['t']=='new') {
$sql="INSERT INTO `tbl_news`(title,writer,shortdesc,longdesc,date,img) VALUES (:title,:writer,:shortdesc,:longdesc,:date,:img)"; $result=$connect->prepare($sql); $query=$result->execute($arr);die('ok');}else if($_GET['t']=="edit") {if(!isset($_GET['id'])) exit('<meta http-equiv="refresh" content="0;url='.$sender_page.'">');if(!is_numeric($_GET['id'])) exit('<meta http-equiv="refresh" content="0;url='.$sender_page.'">');
$title=$_POST['title']; $writer=$_POST['writer']; $shortdesc=$_POST['shortdesc']; $longdesc=$_POST['longdesc']; $date=$_POST['date'];
$sql_update1="UPDATE `tbl_news` SET `title`=:name, `modir_name`=:modir, `tell`=:tell, `mobile`=:mobile, `adres`=:adres, `tarikh_tasis`=:tasis, `tarikh_ezdevaj`=:ezdevaj WHERE `id`='".$_GET['id']."'"; $result_update1=$connect->prepare($sql_update1); $result_update1->bindParam(':name',$name); $result_update1->bindParam(':modir',$modir); $result_update1->bindParam(':tell',$tell); $result_update1->bindParam(':mobile',$mobile); $result_update1->bindParam(':adres',$adres); $result_update1->bindParam(':tasis',$tasis); $result_update1->bindParam(':ezdevaj',$ezdevaj); $res=$result_update1->execute();
if($res>0) die('ok');else die('error');}
?>
by each condition it does upload, delete and insert. but it doesn't upload a file....
June 27 2010
April 16, 2013
Subject: Hi, please help me with my php codes
I cannot upload my file that is sent by another page. here is my code:
/** * @author alireza
*/
require_once ('database.php');
$sender_page='../news.php';
if($_GET['t']=="delete") {
if(!isset($_GET['id']))
exit('<meta http-equiv="refresh" content="0;url='.$sender_page.'">');
if(!is_numeric($_GET['id']))
exit('<meta http-equiv="refresh" content="0;url='.$sender_page.'">');
$arr = array(':title' => $_POST['title'],
':writer' =>$_POST['writer'],
':shortdesc' =>$_POST['shortdesc'],
':longdesc' =>$_POST['longdesc'],
':date' =>$_POST['date'],
':img' =>$file );
if($_GET['t']=='new') {
$sql="INSERT INTO `tbl_news`(title,writer,shortdesc,longdesc,date,img)
VALUES (:title,:writer,:shortdesc,:longdesc,:date,:img)";
$result=$connect->prepare($sql);
$query=$result->execute($arr);
die('ok');
}else if($_GET['t']=="edit") {
if(!isset($_GET['id']))
exit('<meta http-equiv="refresh" content="0;url='.$sender_page.'">');
if(!is_numeric($_GET['id']))
exit('<meta http-equiv="refresh" content="0;url='.$sender_page.'">');
if($res>0)
die('ok');
else
die('error');
}
?>
by each condition it does upload, delete and insert. but it doesn't upload a file....