مشکل در اسکریپت خبری دارم

DJ_Baba

Member
مشکل در اسکریپت خبر دارم

با سلام به دوستان این کد رو لطفا ببینید

این اسکریپت خبر هستش که می تونه وارد کنه ویرایش کنه و حذف کنه
ولی کار نمی کنه


فایل صفحه اصلی index.php

PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="rtl">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled 1</title>
<style type="text/css">
.style1 {
background-color: #E2F3FE;
}
</style>
</head>

<body>
<?php
include("config.php");
/* کد زیر برای دریافت تمام اخبار و چاپ کردن آن ها می باشد */
$sql = mysql_query("select * from news order by news_id desc") or die(mysql_error());
while($fe=mysql_fetch_array($sql)){
?>

<table cellspacing="1" cellpadding="2" width="500">
<tr>
<td bgcolor="#003399" style="color:white"><?php print $fe[news_title]?></td>
</tr>
<tr>
<td><?php print $fe[news_content]?></td>
</tr>
</table><br/>
<? } ?>
</body>

</html>

فایل config.php

PHP:
<?php
$host = 'localhost';
$user = 'news';
$pass = '123456';
$db = "news" ;
mysql_connect($host,$user,$pass) or die (mysql_error()) ;
mysql_select_db($db) ;
?>

فایل وارد کردن خبر add_news.php

PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
	<html xmlns="http://www.w3.org/1999/xhtml" dir="rtl">

	<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>ثبت خبر</title>
	</head>

	<body>
	<form method="post" action="?save">
	<label>عنوان خبر : <input type="text" name="title"/></label><br/>
	<label>متن خبر : </label> <textarea name="content" rows="10" cols="50"></textarea><br/>
	<input type="submit" value="ذخیره"/>
	</form>
	<?php

	if(isset($_GET[save])){
	include("config.php"); // فراخوانی فایل تنظیمات بانک اطلاعاتی
	mysql_query("insert into news values(null,'$_POST[title]','$_POST[content]')
	") or die(mysql_error()); // دستور لازم جست ذخیره اطلاعات در بانک اطلاعاتی

	print "<br/>خبر جدید با موفقیت ثبت گردید!<br/>";

	}

	?>
	</body>

	</html>


فایل ویرایش edit.php

PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="rtl">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>لیست اخبار</title>
</head>

<body>
<?php

include("config.php"); // فراخوانی فایل تنظیمات بانک اطلاعاتی

/* در صورتی که کاربر بر روی لینک حذف کلیک کند کد زیر اجرا می شود */
if(isset($_GET[del])){
print $_GET[del] ;
mysql_query("delete from news where news_id='$_GET[del]'") or die(mysql_error());    // کد لازم جهت حذف کردن اطلاعات از بانک اطلاعاتی
print "خبر مورد نظر با موفقیت حذف گردید!";

}

?>
<ul>
<?php
/* کد زیر برای دریافت تمام اخبار و چاپ کردن آن ها می باشد */
$sql = mysql_query("select * from news order by news_id desc") or die(mysql_error());
while($fe=mysql_fetch_array($sql)){
?>
<li>
<?php print $fe[news_title]?> <a href="edit.php?id=<?php print $fe[news_id]?>">
[ویرایش]</a>  <a href="?del=<?php print $fe[news_title]?>"> [حذف]</a>
</li>
<?php } ?>
</ul>

</body>

</html>


فایل لیست list.php

PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="rtl">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ویرایش خبر</title>
</head>

<body>
<?php

include("config.php");
if(isset($_GET[save])){

mysql_query("update news set news_title='$_POST[title]',news_content='$_POST[content]' where news_id='$_GET[save]'") or die(mysql_error());
print "خبر مورد نظر ویرایش گردید";
print "<br/>";
}
$sql = mysql_query("select * from news where news_id='$_GET[id]' limit 1") or die(mysql_error()); // کد لازم حه دریافت خبر از بانک اطلاعاتی
$fe = mysql_fetch_assoc($sql);
?>
<form method="post" action="?save=<?php print $fe[news_id]?>">
<label>عنوان خبر : <input type="text" name="title" value="<?php print $fe[news_title]?>"/></label><br/>
<label>متن خبر : </label> <textarea name="content" rows="10" cols="50"><?php print $fe[news_content] ?></textarea><br/>
<input type="submit" value="ذخیره"/>
</form>

</body>

</html>
 
آخرین ویرایش:

Goback

Member
سلام،
خطایی چیزی؟؟
اگه خطا میده بذار ،مشکلتم بگو کجای کاره؟ویرایش؟حذف؟...
 

DJ_Baba

Member
این شکل پایگاه داده منه
phpmyadmin1.png


توی بخش نمایش یعنی index متن خبر میاد ولی فقط یکیش میاد بدم فقط موضوع خبر میاد یعنی کلید ادامه مطلب نمیاد

توی بخش ویرایش edit.php لیست خبرها میاد ولی ویرایش کار نمیکنه حذف هم کار نمیکنه
 

Goback

Member
مشکل نمایش خبر

اینو جایگزین کن تو index.php
PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="rtl">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled 1</title>
<style type="text/css">
.style1 {
background-color: #E2F3FE;
}
</style>
</head>

<body>
<?php
include("config.php");
/* کد زیر برای دریافت تمام اخبار و چاپ کردن آن ها می باشد */
$sql = mysql_query("select * from news order by news_id desc") or die(mysql_error());
while($fe=mysql_fetch_array($sql)){
?>

<table cellspacing="1" cellpadding="2" width="500">
<tr>
<td bgcolor="#003399" style="color:white"><?php print $fe['news_title']?></td>
</tr>
<tr>
<td><?php print $fe['news_content']?></td>
</tr>
</table><br/>
<?php } ?>
</body>

</html>
 

Goback

Member
برای مشکل ویرایشتم،همون مشکل صفحه index رو داری،ببین:
PHP:
$_GET['del']  با $_GET[del] فرق داره
دومی اشتباست،یعنی به صورت ثابت بهش نگاه میکنه،ثابتی که تعریف نشده،که خطا میده،پس همه ی آرایه های با اندیس رشته ای رو اینجوری بنویس که نوشتم.
برا ویرایش یا حذف هم میتونی از یه فیلد یونیک استفاده کنی،الآن اینجا فقط برای حذف کار میکنه،اونم به شرطی که آرایه هاتو درست کنی.و برای ویرایش کدی ننوشتی که کار کنه.
اینجوری درستش کن،بعد صفحه edit.php رو گوش به زنگ بذار که مقادیر رو بگیره و کار مربوطه رو بکنه:
PHP:
<ul>
<?php
while($fe=mysql_fetch_array($sql)){
?>
<li>
<?php print $fe['news_title']?> : <a href="edit.php?mod=<?php print $fe['id']?>">[ویرایش]</a> | <a href="edit.php?del=<?php print $fe['id']?>"> [حذف]</a>
</li>
<?php } ?>
</ul>
 

DJ_Baba

Member
اینو جایگزین کن تو index.php
PHP:
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="rtl">

<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>untitled 1</title>
<style type="text/css">
.style1 {
background-color: #e2f3fe;
}
</style>
</head>

<body>
<?php
include("config.php");
/* کد زیر برای دریافت تمام اخبار و چاپ کردن آن ها می باشد */
$sql = mysql_query("select * from news order by news_id desc") or die(mysql_error());
while($fe=mysql_fetch_array($sql)){
?>

<table cellspacing="1" cellpadding="2" width="500">
<tr>
<td bgcolor="#003399" style="color:white"><?php print $fe['news_title']?></td>
</tr>
<tr>
<td><?php print $fe['news_content']?></td>
</tr>
</table><br/>
<?php } ?>
</body>

</html>


دوست عزیز من مشکلم به صورت کامل حل نشده، من می خوام که لینک باشه که بگه ادامه مطلب وقتی روش کلیک شد کل خبر رو نمایش بده
 

Goback

Member
دوست عزیز من مشکلم به صورت کامل حل نشده، من می خوام که لینک باشه که بگه ادامه مطلب وقتی روش کلیک شد کل خبر رو نمایش بده
خب برادر من،ببین شما به جدولت یه فیلد excerpt اضافه کن که مطلب خلاصه توش ذخیره شه،موقع نمایش صفحه اخبار به جای content اینو نشون بده،بعد یه لینک بذار مثل همون ویرایش که یه کوئری استرینگ به صفحه بفرسته و یه کد هم بذار که گوش به زنگ کوئری استرینگ باشه و وقتی دریافتش کرد مقادیر فیلد content رو بخونه و نمایش بده.
اگرم با این روش حال نمیکنی یه سری بزن به اینجا.
موفق باشی
 

DJ_Baba

Member
خب برادر من،ببین شما به جدولت یه فیلد excerpt اضافه کن که مطلب خلاصه توش ذخیره شه،موقع نمایش صفحه اخبار به جای content اینو نشون بده،بعد یه لینک بذار مثل همون ویرایش که یه کوئری استرینگ به صفحه بفرسته و یه کد هم بذار که گوش به زنگ کوئری استرینگ باشه و وقتی دریافتش کرد مقادیر فیلد content رو بخونه و نمایش بده.
اگرم با این روش حال نمیکنی یه سری بزن به اینجا.
موفق باشی


مرسی رفتم دیدم

فقط شما می تونید یه لطفی کنید وقتی رو titile کلیک کرد متن خبر رو نمایش بده

چون من اصلا سر متوجه نشدم و زیاد با php آشنا نیستم
 

Goback

Member
مرسی رفتم دیدم

فقط شما می تونید یه لطفی کنید وقتی رو titile کلیک کرد متن خبر رو نمایش بده

چون من اصلا سر متوجه نشدم و زیاد با php آشنا نیستم

فرض میکنیم که صفحه page.php مطلب کامل یه خبر رو نشون میده.
و صفحه index.php هم خلاصه اخبار رو نشون میده.
index.php:
PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="rtl">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled 1</title>
<style type="text/css">
.style1 {
background-color: #E2F3FE;
}
</style>
</head>

<body>
<?php
include("config.php");
/* ُ ӭѠɑȭ Бʠˣȣ ȎɇѠ栍ǁ ّФ ä 懠䭠ɇՏ */
$sql = mysql_query("select * from news order by news_id desc") or die(mysql_error());
while($fe=mysql_fetch_array($sql)){
?>

<table cellspacing="1" cellpadding="2" width="500">
<tr>
<td bgcolor="#003399" style="color:white"><a href="page.php?id=<?php echo $fe['news_id']; ?>"><?php print $fe['news_title']?></a></td>
</tr>
<tr>
<td><?php print $fe['news_content']?></td>
</tr>
</table><br/>
<?php } ?>
</body>

</html>
صفحه page.php رو هم گوش به زنگش خیلی نذار! :)
فقط دقت کن کد اضافه شده اینه:
PHP:
<a href="page.php?id=<?php echo $fe['news_id']; ?>"><?php print $fe['news_title']?></a>
امیدوارم مشکلت حل شده باشه دوست گرام.(قدیما یه تشکری هم میکردن:green: البته با دکمه تشکر هم کارت راه میفته)
 

DJ_Baba

Member
فرض میکنیم که صفحه page.php مطلب کامل یه خبر رو نشون میده.
و صفحه index.php هم خلاصه اخبار رو نشون میده.
index.php:
PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="rtl">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled 1</title>
<style type="text/css">
.style1 {
background-color: #E2F3FE;
}
</style>
</head>

<body>
<?php
include("config.php");
/* ُ ӭѠɑȭ Бʠˣȣ ȎɇѠ栍ǁ ّФ ä 懠䭠ɇՏ */
$sql = mysql_query("select * from news order by news_id desc") or die(mysql_error());
while($fe=mysql_fetch_array($sql)){
?>

<table cellspacing="1" cellpadding="2" width="500">
<tr>
<td bgcolor="#003399" style="color:white"><a href="page.php?id=<?php echo $fe['news_id']; ?>"><?php print $fe['news_title']?></a></td>
</tr>
<tr>
<td><?php print $fe['news_content']?></td>
</tr>
</table><br/>
<?php } ?>
</body>

</html>
صفحه page.php رو هم گوش به زنگش خیلی نذار! :)
فقط دقت کن کد اضافه شده اینه:
PHP:
<a href="page.php?id=<?php echo $fe['news_id']; ?>"><?php print $fe['news_title']?></a>
امیدوارم مشکلت حل شده باشه دوست گرام.(قدیما یه تشکری هم میکردن:green: البته با دکمه تشکر هم کارت راه میفته)

اول : من خیلی شرمندم یادم رفته بود تشکر
دوم : ببین یه چیزی میگم اعصبانی شنو :mad:
من الان صفحه ای ندارم به page.php اگه بخوام درست کنم باید چی بنویسم توش و این کد :
PHP:
<a href="page.php?id=<?php echo $fe['news_id']; ?>"><?php print $fe['news_title']?></a>

کجاش بنویسم؟

بازم شرمنده
 

Goback

Member
دوم : ببین یه چیزی میگم اعصبانی شنو :mad:
من الان صفحه ای ندارم به page.php اگه بخوام درست کنم باید چی بنویسم توش و این کد :
PHP:
<a href="page.php?id=<?php echo $fe['news_id']; ?>"><?php print $fe['news_title']?></a>
کجاش بنویسم؟

بازم شرمنده
دشمنت شرمنده بشه ایشالا،فعلا بیکاریم و چون بلد نیستیم جواب میدیم یه چی هم خودمون یاد بگیریم.:cool:
نداری خوب باید بسازی دیگه! به قول یه بنده خدایی درس خارجکی که نیست :)
index.php که همین قبلیه،اینم صفحه page.
page.php
PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="rtl">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled 1</title>
<style type="text/css">
.style1 {
background-color: #E2F3FE;
}
</style>
</head>

<body>
<?php
include("config.php");
/* کد زير براي دريافت تمام اخبار و چاپ کردن آن ها مي باشد */
if(isset($_GET['id'])){
$sql = mysql_query("select * from news where news_id=\"$_GET['id']\"") or die(mysql_error());
$fe=mysql_fetch_array($sql))
?>

<table cellspacing="1" cellpadding="2" width="500">
<tr>
<td bgcolor="#003399" style="color:white"><?php print $fe['news_title']?></td>
</tr>
<tr>
<td><?php print $fe['news_content']?></td>
</tr>
</table><br/>
<?php } ?>
</body>

</html>
در ضمن اگه حل نشد بپرس بچه ها هستن ،جواب میدن.
یا زهــــرا س
 

DJ_Baba

Member
دشمنت شرمنده بشه ایشالا،فعلا بیکاریم و چون بلد نیستیم جواب میدیم یه چی هم خودمون یاد بگیریم.:cool:
نداری خوب باید بسازی دیگه! به قول یه بنده خدایی درس خارجکی که نیست :)
index.php که همین قبلیه،اینم صفحه page.
page.php
PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="rtl">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled 1</title>
<style type="text/css">
.style1 {
background-color: #E2F3FE;
}
</style>
</head>

<body>
<?php
include("config.php");
/* کد زير براي دريافت تمام اخبار و چاپ کردن آن ها مي باشد */
if(isset($_GET['id'])){
$sql = mysql_query("select * from news where news_id=\"$_GET['id']\"") or die(mysql_error());
$fe=mysql_fetch_array($sql))
?>

<table cellspacing="1" cellpadding="2" width="500">
<tr>
<td bgcolor="#003399" style="color:white"><?php print $fe['news_title']?></td>
</tr>
<tr>
<td><?php print $fe['news_content']?></td>
</tr>
</table><br/>
<?php } ?>
</body>

</html>
در ضمن اگه حل نشد بپرس بچه ها هستن ،جواب میدن.
یا زهــــرا س


ممنون بابت لطفت

ببین من این کدارو اینجا آپلود کردم http://www.heatfender.com/news/
ولی کار نمیکنه و این خطا رو میده
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator to inform of the time the error occurred and of anything you might have done that may have caused the error.

More information about this error may be available in the server error log.
 

Goback

Member
ممنون بابت لطفت

ببین من این کدارو اینجا آپلود کردم http://www.heatfender.com/news/
ولی کار نمیکنه و این خطا رو میده
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator to inform of the time the error occurred and of anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

اینو دیگه باید از سرویس دهنده هاستت بپرسی،ضمن اینکه از اسکریپت index.php آخری رو استفاده کن که لینک به مطلب اصلی میداد،چون مقدار id اصلا مشخص نشده.
کد:
http://www.heatfender.com/news/page.php?id=
در صورتی که مثلا باید اینجوری باشه:
کد:
http://www.heatfender.com/news/page.php?[B]id=1[/B]
نشد،خصوصی بده/ت
 

DJ_Baba

Member
اینو دیگه باید از سرویس دهنده هاستت بپرسی،ضمن اینکه از اسکریپت index.php آخری رو استفاده کن که لینک به مطلب اصلی میداد،چون مقدار id اصلا مشخص نشده.
کد:
http://www.heatfender.com/news/page.php?id=
در صورتی که مثلا باید اینجوری باشه:
کد:
http://www.heatfender.com/news/page.php?[B]id=1[/B]
نشد،خصوصی بده/ت

ببین من چطوری به news_id مقدار دهی کنم تا هربار من می خوام خبر جدید وارد کنم خود سیستم اتوماتیک یه آی دی به خبر بده

این کد وارد کردن خبره

PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" dir="rtl">

    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>ثبت خبر</title>
    </head>

    <body>
    <form method="post" action="?save">
    <label>عنوان خبر : <input type="text" name="title"/></label><br/>
    <label>متن خبر : </label> <textarea name="content" rows="10" cols="50"></textarea><br/>
    <input type="submit" value="ذخیره"/>
    </form>
    <?php

    if(isset($_GET[save])){
    include("config.php"); // فراخوانی فایل تنظیمات بانک اطلاعاتی
    mysql_query("insert into news values(null,'$_POST['title']','$_POST['content']')
    ") or die(mysql_error()); // دستور لازم جست ذخیره اطلاعات در بانک اطلاعاتی

    print "<br/>خبر جدید با موفقیت ثبت گردید!<br/>";

    }

    ?>
    </body>

    </html>
 

Goback

Member
ببین من چطوری به news_id مقدار دهی کنم تا هربار من می خوام خبر جدید وارد کنم خود سیستم اتوماتیک یه آی دی به خبر بده

این کد وارد کردن خبره

PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" dir="rtl">

    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>ثبت خبر</title>
    </head>

    <body>
    <form method="post" action="?save">
    <label>عنوان خبر : <input type="text" name="title"/></label><br/>
    <label>متن خبر : </label> <textarea name="content" rows="10" cols="50"></textarea><br/>
    <input type="submit" value="ذخیره"/>
    </form>
    <?php

    if(isset($_GET[save])){
    include("config.php"); // فراخوانی فایل تنظیمات بانک اطلاعاتی
    mysql_query("insert into news values(null,'$_POST['title']','$_POST['content']')
    ") or die(mysql_error()); // دستور لازم جست ذخیره اطلاعات در بانک اطلاعاتی

    print "<br/>خبر جدید با موفقیت ثبت گردید!<br/>";

    }

    ?>
    </body>

    </html>
اینجوری:
PHP:
mysql_query("insert into news(title,content) values('$_POST['title']','$_POST['content']'")
 

DJ_Baba

Member
اینجوری:
PHP:
mysql_query("insert into news(title,content) values('$_POST['title']','$_POST['content']'")

ببین این کد هیچ مقداری به new_id نمیده
اگه یادت باشه اخبار به خاطر این باز نمی شن که هیچ آی دی نداره خبرهای درج شده

حالا من می خوام تویی بخش خبر وفتی دارم اخباری رو وارد می کنم یک ID به خبر بده تا توی صفحه اصلی بشه با ID باز کرد خبر رو


مرسی
 

Goback

Member
ببین این کد هیچ مقداری به new_id نمیده
اگه یادت باشه اخبار به خاطر این باز نمی شن که هیچ آی دی نداره خبرهای درج شده

حالا من می خوام تویی بخش خبر وفتی دارم اخباری رو وارد می کنم یک id به خبر بده تا توی صفحه اصلی بشه با id باز کرد خبر رو


مرسی
همین کاری رو که گفتم انجام بده،آی دی چون به صورت اتوماتیک تعریف شده،خودش مشخص میشه.
 

جدیدترین ارسال ها

بالا