PDA

View Full Version : مبتدی: ویرایش فرم



bravia2009
جمعه 25 تیر 1389, 14:21 عصر
با سلام خدمت دوستان محترم و ضمن عرض تبریک به همه دوستان به مناسبت اعیاد
من توی فرمم میخوام ویرایش اضافه کنم الان فرم به شکل زیره
مشکلم اینه که چرا الان مقادیر از دیتا بیس نمیاره .مقادیر از دیتا بیس توی فرمم نمایش نمیده مثلا در اولی که اسم فرم مقدار value هم قرار دادم ولی بازم الان مشکل این جاست که نمایش نمیده درواقع مقدار نام فرم نمیاره

<!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" xml:lang="en" lang="en">

<head>
<meta http-equiv="Content-type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-language" content="fa">

<meta name="author" content="saeed" />

<title> صفحه ویرایش </title>
</head>

<body>


<?php
function getrecord($id,$link){
// if (isset($_GET['do']) && $_GET['do']=='edit'){

include_once("db.php");
$result=mysql_fetch_array(mysql_query("select dId,dName,dBody from document where dId=$id",$link));
return $result;
}
$result=getrecord(1,$link);
for ($i=0;$i<count($result)/2;$i++)
{
echo '<tr>
<td>نام سند :</td>
<td><input type="text" align="RIGHT" name="dName" maxlength="" value="'.$result[$i].'"/></td>
</tr>';
echo ' <tr>
<td>تاریخ درج :</td>
<td><input type="text" align="RIGHT" name="dInDate" /></td>
</tr>';
echo ' <tr>
<td>محل درج متن :</td>
<td><textarea wrap="OFF" name="dBody"></textarea></td>
</tr>';
echo ' <tr>
<td></td>
<td><input type="submit" name="dSend" value="ارسال" /></td>';
}

?>

</table>
</body>
</html>

صابر طهماسبی
جمعه 25 تیر 1389, 15:13 عصر
سلام
کد بانکتون و db.php رو به صورت zip ضمیمه کنید شاید بتونم راهنمایی کنم

bravia2009
جمعه 25 تیر 1389, 15:24 عصر
سلام ممنونم از لطفت
1.کد دیتا بیس :

<?php

/**
* @author saeed
* @copyright 2010
*/

$host='localhost';//variable for define database
$username='admin';//variable for define database
$password='110';//variable for define database
$dbname='softechcms';//variable for define database select
$dbtable='document';//variable for define database select
$link=mysql_connect($host,$username,$password) or die ("Your connecting have error");
//coonect to data base with user and password
$db=mysql_select_db($dbname,$link) or die ("Your sql have error");//selec database and connect



?>
2.کدصفحه نمایش رکورد ها
2.1 - دکمه حذف با زحمات شما نوشته شده است
2.2 کار برای دکمه ویرایش است

<!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" xml:lang="en" lang="en">

<head>

<meta http-equiv="Content-type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-language" content="fa">

<meta name="author" content="saeed" />

<title> مشاهده جداول پایگاه داده </title>
</head>

<body>
<!-- begining code -- >
<div style="text-align:center;">

<table width="800" border="1" align="center" dir="rtl" style="font-family: Tahoma;
font-size: 12px;" cellpadding="10" cellspacing="10">


<caption><b> جدول مشاهده مستندات </b></caption>

<a href="new.php?do=new">
<img src="Picture/1.png" alt="add message pic" name="Add" width="128" height="128" title="ایجاد پیام"/>
</a>
</div>

<thead style="background: aqua;">
<tr>
<th width="40" height="40" scope="col"> <b> کد سند </b></th>
<th width="160" height="40" scope="col"> <b> نام فرستنده </b></th>
<th width="200" height="40" scope="col" > <b> تاریخ درج </b></th>
<th width="600" height="40" scope="col" > <b> متن فایل </b></th>
<th width="200" height="40" scope="col" > <b> امکانات </b></th>
</tr>
</thead>




<!--endinig header code -- >
<?php

include_once('db.php');// link to other page
$action=$_GET['do'];
switch($action)
{
case "delete": DeleteRecord();break;
case "edit": edit();break;
default:break;

}
// case "delete":
function DeleteRecord()
{
//$do=$_REQUEST['do'];

if(isset($_GET['do']) && $_GET['do'] == 'delete' ){
$id=$_GET['id'];

$query="delete from document where dId = $id";
global $link;
$result=mysql_query($query,$link) ;
if(!$result){
echo 'Error deleting record!';

}






}
}





$query="select dId,dName,dInDate,dBody from document ORDER by dInDate desc";//getting row in document table
$result=mysql_query($query,$link);//set in the variable with mysql_query
$num=mysql_num_rows($result);//getting row for loop for and with result
for ($i=0;$i<$num;$i++){
$row=mysql_fetch_array($result);//getting
echo '<tr>';
echo "<td> $row[dId]</td>";
echo "<td> $row[dName] </td>" ;
echo "<td> $row[dInDate] </td>" ;
echo "<td> $row[dBody]</td>";

$id=$row[0];
echo '<td><b><a href="view.php?do=edit&id='."$row[0]".'"><img src="picture/3.png" alt= ویرایش name="edit" width="32" height="30" title=" ویرایش" /></a></b> ';// Edit row from datebase

echo '<b><a href="view.php?do=delete&id='."$row[0]".'"><img src="picture/2.png" alt="حذف" name="delete" width="32" height="30" title="حذف" /></a></b> </td>'; //Delete row from Datebase







}
3.صفحه ویرایش که خودم یکسری کدشا زدم و لی نتیجه نداده و به مشکل خوردم

<!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" xml:lang="en" lang="en">

<head>
<meta http-equiv="Content-type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-language" content="fa">

<meta name="author" content="saeed" />

<title> صفحه ویرایش </title>
</head>

<body>
<form method="post" action="">
<table align="center" dir="rtl" style="font-family: Tahoma; font-size: 12px;">

<tr>
<td>نام سند :</td>
<td><input type="text" align="RIGHT" name="dName" maxlength=""/></td>
</tr>
<td>
<tr>
<td> فایل ضمیمه :</td>
<td><input type="file" size="20" name="dFile" /></td>
</tr>

<tr>
<td>تاریخ درج :</td>
<td><input type="text" align="RIGHT" name="dInDate" /></td>
</tr>
<tr>
<td>محل درج متن :</td>
<td><textarea wrap="OFF" name="dBody"></textarea></td>
</tr>

<tr>
<td></td>
<td><input type="submit" name="dSend" value="ارسال" /></td>

</tr>
</table>
<table align="center" dir="rtl" style="font-family: Tahoma; font-size: 12px;" >

<?php
function getrecord($id,$link){
// if (isset($_GET['do']) && $_GET['do']=='edit'){

include_once("db.php");
// $result=mysql_fetch_array(mysql_query("select dId,dName,dBody from document where dId=$id",$link));
//return $result;
// $query="select dId,dName,dInDate,dBody from document";
// $result=mysql_query($query,$link);
//$num=mysql_num_rows($result);

}
// $result=getrecord(1,$link);
for ($i=0;$i<count($result)/2;$i++)
{
$rows=mysql_fetch_array($result);

echo '<tr>
<td>نام سند :</td>
<td><input type="text" align="RIGHT" name="dName" maxlength="" value=""/></td>
</tr>';
echo ' <tr>
<td>تاریخ درج :</td>
<td><input type="text" align="RIGHT" name="dInDate" /></td>
</tr>';
echo ' <tr>
<td>محل درج متن :</td>
<td><textarea wrap="OFF" name="dBody"></textarea></td>
</tr>';
echo ' <tr>
<td></td>
<td><input type="submit" name="dSend" value="ارسال" /></td>';

}
?>

</table>
</body>
</html>
با تشکر فراوان

mohmadd
جمعه 25 تیر 1389, 19:12 عصر
سلام
نکته : اسم فیلد های دیتابیس رو با name یا id تگ ها یکی نباشه از نظر امنیتی مشکل داره. حلقه ای که در تاپیک قبلی داده بودم فقط یه مثال بود چون اینجا خودت تمامی تگ هارو تایپ کردی دیگه نیازی نیست
باید از متغییر $result که محتوای یک line از id مربوطه هستش استفاده بشه ...



$result[0];//=dId
$result[1];//=dName
$result[2];//=dBody

<!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" xml:lang="en" lang="en">

<head>
<meta http-equiv="Content-type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-language" content="fa">

<meta name="author" content="saeed" />

<title> صفحه ویرایش </title>
</head>

<body>


<?php


include_once("db.php");
function getrecord($id,$link)
{
$result=mysql_fetch_array(mysql_query("select dId,dName,dBody from document where dId = $id",$link));
return $result;
}
if(!$_GET['do']=='edit' && ($id=$_GET['id'])>0)
die('type error ...');

$result=getrecord($id,$link);


echo '<form method="post" action="">
<table align="center" dir="rtl" style="font-family: Tahoma; font-size: 12px;">';

echo '<tr>
<td>نام سند :</td>
<td><input type="text" align="RIGHT" name="dName" maxlength="" value="'.$result[1].'"/></td>
</tr>';
echo ' <tr>
<td>تاریخ درج :</td>
<td><input type="text" align="RIGHT" name="dInDate" /></td>
</tr>';
echo ' <tr>
<td>محل درج متن :</td>
<td><textarea wrap="OFF" name="dBody">'.$result[2].'</textarea></td>
</tr>';
echo ' <tr>
<td></td>
<td><input type="submit" name="dSend" value="ارسال" /></td>';

echo ' </tr>
</table> </form>';



?>


</body>
</html>