PDA

View Full Version : مشکل این کد چیه؟؟؟



milad_d993
شنبه 25 خرداد 1392, 17:35 عصر
سلام دوستان
میشه یه نگاه کنین ببینین چرا خطا میده من که چشمام خسته شد از بس نگاه کردم
خطا از لاین 210 هستش



<?php
session_start();

if (!(isset($_SESSION["adminLogin"]) and $_SESSION["adminLogin"] == "yes")){
echo "<script language='javascript'>window.location.href='../login.php'</script>";
}

function redirect ($page){
$s = "<script language='javascript'>
window.location.href='$page'
</script>";
return $s;
}

if (isset($_SERVER['HTTP_REFERER'])){

$insert = "/bookstore/admin/book/insertbook.php";
$update = "/bookstore/admin/book/updateBook.php";
$list = "/bookstore/admin/book/listbook.php";
$index = "/bookstore/admin/index.php";
$search = "/bookstore/search.php";

$a=parse_url($_SERVER['HTTP_REFERER']);
foreach($a as $b){
if ($b == $insert){
$p = "INSERT";
}elseif($b == $update){
$p = "UPDATE";
}elseif($b == $list or $b == $index ){
$p = "DELETE";
}elseif($b == $search){
$p = "SEARCH";
}
}

if (isset ($p) and $p == "INSERT" || $p == "UPDATE"){

$book_id = $_POST["book_id"];
$name = $_POST["name"];
$category= "";
$author = $_POST["author"];
$publisher = $_POST["publisher"];
$ISBN = $_POST["ISBN"];
$price = $_POST["price"];
$year = $_POST["year"];
$pages = $_POST["pages"];
$language = "";
$description = $_POST["description"];

if (isset($_POST["language"])) { $language = $_POST["language"]; }

if (isset($_POST["category"])){
$c= $_POST["category"];
$n=count($c);
for ($i=0;$i<$n;$i++){
if ($i < $n-1){
$category.= "$c[$i],";
}else{
$category.= $c[$i];
}
}
}
}

//INSERT
if (isset ($p) and $p == "INSERT"){

$photo_link = "photos/nophoto.jpg";
$file_link = "";

if (is_uploaded_file($_FILES['photo_link']['tmp_name'])){
$photo_path = "photos/";
$photo_extension = substr($_FILES['photo_link']['name'],$_FILES['photo_link']['name']-4);

if (substr($photo_extension,0,1) != "."){ // for .jpeg
$photo_extension = substr($_FILES['photo_link']['name'],$_FILES['photo_link']['name']-5);
}

$photo_link = $photo_path.$book_id.$photo_extension;
move_uploaded_file($_FILES['photo_link']['tmp_name'],$photo_link);
}

if (is_uploaded_file($_FILES['file_link']['tmp_name'])){
$file_path = "files/";
$file_extension = substr($_FILES['file_link']['name'],-4);

if (substr($file_extension,0,1) != "."){ // for .docx & .fodt
$file_extension = substr($_FILES['file_link']['name'],-5);
}

$file_link = $file_path.$book_id.$file_extension;
move_uploaded_file($_FILES['file_link']['tmp_name'],$file_link);
}

require_once("C:\wamp\www\bookstore\DBconfig.php");
$book_result = mysql_query("select * from book where book_id='$book_id'",$serverLink);
if (mysql_num_rows($book_result) == 0){

mysql_query("insert into book values('$book_id',
'$name',
'$category',
'$photo_link',
'$file_link',
'$author',
'$publisher',
'$ISBN',
'$price',
'$year',
'$pages',
'$language',
'$description')",$serverLink);

mysql_close($serverLink);
echo redirect("listbook.php?msg=insert&id=$book_id&name=$name&author=$author");

}else{
mysql_close($serverLink);
echo redirect("insertbook.php");
}

//UPDATE
}elseif (isset ($p) and $p == "UPDATE"){

require_once("C:\wamp\www\bookstore\DBconfig.php");
$book_result = mysql_query("select * from book where book_id='$book_id'",$serverLink);
$book_record = mysql_fetch_assoc($book_result);
$photo_link = $book_record["photo_link"];
$file_link = $book_record["file_link"];

if (is_uploaded_file($_FILES['photo_link']['tmp_name'])){
if ($photo_link != "photos/nophoto.jpg"){
if(file_exists($photo_link)) unlink($photo_link);
}
$photo_path = "photos/";
$photo_extension = substr($_FILES['photo_link']['name'],-4);

if (substr($photo_extension,0,1) != "."){ // for .jpeg
$photo_extension = substr($_FILES['photo_link']['name'],-5);
}

$photo_link = $photo_path.$book_id.$photo_extension;
move_uploaded_file($_FILES['photo_link']['tmp_name'],$photo_link);
}

if (is_uploaded_file($_FILES['file_link']['tmp_name'])){
if(file_exists($file_link)) unlink($file_link);
$file_path = "files/";
$file_extension = substr($_FILES['file_link']['name'],-4);

if (substr($file_extension,0,1) != "."){ // for .docx & .fodt
$file_extension = substr($_FILES['file_link']['name'],-5);
}

$file_link = $file_path.$book_id.$file_extension;
move_uploaded_file($_FILES['file_link']['tmp_name'],$file_link);
}

mysql_query("UPDATE book SET name = '$name',
category = '$category',
photo_link = '$photo_link',
file_link = '$file_link',
author = '$author',
publisher = '$publisher',
ISBN = '$ISBN',
price = '$price',
year = '$year',
pages = '$pages',
language = '$language',
description = '$description'
where book_id = '$book_id'", $serverLink);

$shopResult = mysql_query("select count(*) from shopping where book_id='$book_id'",$serverLink);
$shop = mysql_fetch_array($shopResult);
if ($shop[0] > 0){
mysql_query("UPDATE shopping SET book_name ='$name' where book_id='$book_id'",$serverLink);
}
mysql_close($serverLink);
echo redirect("listbook.php?msg=update&id=$book_id&name=$name&author=$author");

//DELETE
}elseif (isset ($p) and $p == "DELETE"){
$id = $_GET["id"];
require_once("C:\wamp\www\bookstore\DBconfig.php");
$book_result = mysql_query("select * from book where book_id='$id'",$serverLink);
$book_record = mysql_fetch_assoc($book_result);
$name= $book_record["name"];
$author= $book_record["author"];

mysql_query("Delete from book Where book_id ='$id'",$serverLink);

if ($book_record["photo_link"] != "photos/nophoto.jpg"){
if(file_exists($book_record["photo_link"])) unlink($book_record["photo_link"]);
}
if(file_exists($book_record["file_link"])) unlink($book_record["file_link"]);

mysql_close($serverLink);
echo redirect("listbook.php?msg=delete&id=$id&name=$name&author=$author");

//SEARCH
}elseif (isset ($p) and $p == "SEARCH"){
$sql = "select * from book";
if (isset ($_POST["bookName"])){

}

}
}else{
echo redirect("listbook.php");
}
}else{
echo redirect("listbook.php");
}

?>

morudi
شنبه 25 خرداد 1392, 17:40 عصر
میشه ارور رو که میده بنویسید

milad_d993
شنبه 25 خرداد 1392, 17:54 عصر
مشکل بخاطر تیکه کد پایین بود که یادم رفته بود قبلا نوشته بودمش...
خط 199 تا 206


//SEARCH
}elseif (isset ($p) and $p == "SEARCH"){
$sql = "select * from book";
if (isset ($_POST["bookName"])){

}

}

morudi
شنبه 25 خرداد 1392, 17:57 عصر
برادر من اروری رو که می ده بنویس

milad_d993
شنبه 25 خرداد 1392, 21:35 عصر
Parse error: parse error in C:\wamp\www\bookstore\admin\book\operationbook.php on line 210

morudi
شنبه 25 خرداد 1392, 22:10 عصر
دوست گلم یه اکولاد اضافه گذاشتی
و خطای دومت اینه که یا ; و یا یکی از کوتیشن هات فراموش شده

sh.n.n786
شنبه 25 خرداد 1392, 22:24 عصر
درود و ...
کد ویرایش شده :



<?php
session_start();

if (!(isset($_SESSION["adminLogin"]) and $_SESSION["adminLogin"] == "yes")){
echo "<script language='javascript'>window.location.href='../login.php'</script>";
}

function redirect ($page){
$s = "<script language='javascript'>
window.location.href='$page'
</script>";
return $s;
}

if (isset($_SERVER['HTTP_REFERER'])){

$insert = "/bookstore/admin/book/insertbook.php";
$update = "/bookstore/admin/book/updateBook.php";
$list = "/bookstore/admin/book/listbook.php";
$index = "/bookstore/admin/index.php";
$search = "/bookstore/search.php";

$a=parse_url($_SERVER['HTTP_REFERER']);
foreach($a as $b){
if ($b == $insert){
$p = "INSERT";
}elseif($b == $update){
$p = "UPDATE";
}elseif($b == $list or $b == $index ){
$p = "DELETE";
}elseif($b == $search){
$p = "SEARCH";
}
}

if (isset ($p) and $p == "INSERT" || $p == "UPDATE"){

$book_id = $_POST["book_id"];
$name = $_POST["name"];
$category= "";
$author = $_POST["author"];
$publisher = $_POST["publisher"];
$ISBN = $_POST["ISBN"];
$price = $_POST["price"];
$year = $_POST["year"];
$pages = $_POST["pages"];
$language = "";
$description = $_POST["description"];

if (isset($_POST["language"])) { $language = $_POST["language"]; }

if (isset($_POST["category"])){
$c= $_POST["category"];
$n=count($c);
for ($i=0;$i<$n;$i++){
if ($i < $n-1){
$category.= "$c[$i],";
}else{
$category.= $c[$i];
}
}
}
}

//INSERT
if (isset ($p) and $p == "INSERT"){

$photo_link = "photos/nophoto.jpg";
$file_link = "";

if (is_uploaded_file($_FILES['photo_link']['tmp_name'])){
$photo_path = "photos/";
$photo_extension = substr($_FILES['photo_link']['name'],$_FILES['photo_link']['name']-4);

if (substr($photo_extension,0,1) != "."){ // for .jpeg
$photo_extension = substr($_FILES['photo_link']['name'],$_FILES['photo_link']['name']-5);
}

$photo_link = $photo_path.$book_id.$photo_extension;
move_uploaded_file($_FILES['photo_link']['tmp_name'],$photo_link);
}

if (is_uploaded_file($_FILES['file_link']['tmp_name'])){
$file_path = "files/";
$file_extension = substr($_FILES['file_link']['name'],-4);

if (substr($file_extension,0,1) != "."){ // for .docx & .fodt
$file_extension = substr($_FILES['file_link']['name'],-5);
}

$file_link = $file_path.$book_id.$file_extension;
move_uploaded_file($_FILES['file_link']['tmp_name'],$file_link);
}

require_once("C:\wamp\www\bookstore\DBconfig.php") ;
$book_result = mysql_query("select * from book where book_id='$book_id'",$serverLink);
if (mysql_num_rows($book_result) == 0){

mysql_query("insert into book values('$book_id',
'$name',
'$category',
'$photo_link',
'$file_link',
'$author',
'$publisher',
'$ISBN',
'$price',
'$year',
'$pages',
'$language',
'$description')",$serverLink);

mysql_close($serverLink);
echo redirect("listbook.php?msg=insert&id=$book_id&name =$name&author=$author");

}else{
mysql_close($serverLink);
echo redirect("insertbook.php");
}

//UPDATE
}elseif (isset ($p) and $p == "UPDATE"){

require_once("C:\wamp\www\bookstore\DBconfig.php") ;
$book_result = mysql_query("select * from book where book_id='$book_id'",$serverLink);
$book_record = mysql_fetch_assoc($book_result);
$photo_link = $book_record["photo_link"];
$file_link = $book_record["file_link"];

if (is_uploaded_file($_FILES['photo_link']['tmp_name'])){
if ($photo_link != "photos/nophoto.jpg"){
if(file_exists($photo_link)) unlink($photo_link);
}
$photo_path = "photos/";
$photo_extension = substr($_FILES['photo_link']['name'],-4);

if (substr($photo_extension,0,1) != "."){ // for .jpeg
$photo_extension = substr($_FILES['photo_link']['name'],-5);
}

$photo_link = $photo_path.$book_id.$photo_extension;
move_uploaded_file($_FILES['photo_link']['tmp_name'],$photo_link);
}

if (is_uploaded_file($_FILES['file_link']['tmp_name'])){
if(file_exists($file_link)) unlink($file_link);
$file_path = "files/";
$file_extension = substr($_FILES['file_link']['name'],-4);

if (substr($file_extension,0,1) != "."){ // for .docx & .fodt
$file_extension = substr($_FILES['file_link']['name'],-5);
}

$file_link = $file_path.$book_id.$file_extension;
move_uploaded_file($_FILES['file_link']['tmp_name'],$file_link);
}

mysql_query("UPDATE book SET name = '$name',
category = '$category',
photo_link = '$photo_link',
file_link = '$file_link',
author = '$author',
publisher = '$publisher',
ISBN = '$ISBN',
price = '$price',
year = '$year',
pages = '$pages',
language = '$language',
description = '$description'
where book_id = '$book_id'", $serverLink);

$shopResult = mysql_query("select count(*) from shopping where book_id='$book_id'",$serverLink);
$shop = mysql_fetch_array($shopResult);
if ($shop[0] > 0){
mysql_query("UPDATE shopping SET book_name ='$name' where book_id='$book_id'",$serverLink);
}
mysql_close($serverLink);
echo redirect("listbook.php?msg=update&id=$book_id&name =$name&author=$author");

//DELETE
}
elseif (isset ($p) and $p == "DELETE"){
$id = $_GET["id"];
require_once("C:\wamp\www\bookstore\DBconfig.php") ;
$book_result = mysql_query("select * from book where book_id='$id'",$serverLink);
$book_record = mysql_fetch_assoc($book_result);
$name= $book_record["name"];
$author= $book_record["author"];

mysql_query("Delete from book Where book_id ='$id'",$serverLink);

if ($book_record["photo_link"] != "photos/nophoto.jpg"){
if(file_exists($book_record["photo_link"])) unlink($book_record["photo_link"]);
}
if(file_exists($book_record["file_link"])) {
unlink($book_record["file_link"]);
mysql_close($serverLink);
echo redirect("listbook.php?msg=delete&id=$id&name=$nam e&author=$author");
//SEARCH
}
elseif (isset ($p) and $p == "SEARCH"){
$sql = "select * from book";
if (isset ($_POST["bookName"])){
}
}
}
else{
echo redirect("listbook.php");
}
}
else{
echo redirect("listbook.php");
}
?>