PDA

View Full Version : سوال: بازیابی اطلاعات از دیتابیس



mmvalinezhad
چهارشنبه 29 مرداد 1393, 12:04 عصر
سلام خدمت دوستان عزیز
من قصد دارم یک اطلاعات مربوط به یک رکورد خاص از دیتابیس را در فرمی که شامل پارامتر های مربوط به دیتابیس باشد بازیابی کنم و کاربر بعد از تغییر بتواند آن را ذخیره کند و اطلاعات در دیتابیس جایگزین اطلاعات قبلی شود.کد آن به صورت زیر است اما متاسفانه بعد از ذخیره عمل نمی کند و اطلاعات موجود در دیتابیس تغییر نمی کند.لطفا راهنمایی بفرمایید:

<?php


include 'dbc.php';
page_protect();

$err = array();
$msg = array();

if($_POST['doUpdate'] == 'Update')
{


$rs_pwd = mysql_query("select Title from mytable where Title='+titletext+'");
list($old) = mysql_fetch_row($rs_pwd);
$old_salt = substr($old,0,9);



}

if($_POST['doSave'] == 'Save')
{
// Filter POST data for harmful code (sanitize)
foreach($_POST as $key => $value) {
$data[$key] = filter($value);
}


mysql_query("UPDATE mytable SET
`Title` = '$data[Title]',
`Authors` = '$data[Authors]',
`Year` = '$data[Year]',
`Journal` = '$data[Journal]',
`Link` = '$data[Link]',
WHERE Title='$_SESSION['+titletext+']'
") or die(mysql_error());

//header("Location: mysettings.php?msg=mytable Sucessfully Saved");
$msg[] = "mytable Sucessfully Saved";
}

$rs_settings = mysql_query("select * from mytable where Title='+titletext+'");
?>
<html>
<head>
<title>My Account Settings</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script language="JavaScript" type="text/javascript" src="js/jquery.validate.js"></script>
<script>
$(document).ready(function(){
$("#myform").validate();
$("#pform").validate();
});
</script>
<link href="styles.css" rel="stylesheet" type="text/css">
</head>

<body>
<table width="100%" border="0" cellspacing="0" cellpadding="5" class="main">
<tr>
<td colspan="3">&nbsp;</td>
</tr>
<tr>
<td width="160" valign="top"><?php
/*********************** MYACCOUNT MENU ****************************
This code shows my account menu only to logged in users.
Copy this code till END and place it in a new html or php where
you want to show myaccount options. This is only visible to logged in users
************************************************** *****************/
if (isset($_SESSION[+titletext+])) {?>
<div class="myaccount">
<p><strong>My Account</strong></p>
<a href="myaccount.php">My Account</a><br>
<a href="mysettings.php">Settings</a><br>
<a href="logout.php">Logout </a>
<p>You can add more links here for users</p></div>
<?php }
/*******************************END**************** **********/
?>
<?php
if (checkAdmin()) {
/*******************************END**************** **********/
?>
<p> <a href="admin.php">Admin CP </a></p>
<?php } ?>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p></td>
<td width="732" valign="top">
<h3 class="titlehdr">My Account - Settings</h3>
<p>
<?php
if(!empty($err)) {
echo "<div class=\"msg\">";
foreach ($err as $e) {
echo "* Error - $e <br>";
}
echo "</div>";
}
if(!empty($msg)) {
echo "<div class=\"msg\">" . $msg[0] . "</div>";

}
?>
</p>
<p>Here you can make changes to your profile. Please note that you will
not be able to change your email which has been already registered.</p>
<?php while ($row_settings = mysql_fetch_array($rs_settings)) {?>
<form action="mysettings.php" method="post" name="myform" id="myform">
<table width="90%" border="0" align="center" cellpadding="3" cellspacing="3" class="forms">
<tr>
<td colspan="2"> mytable Title:<br> <input name="name" type="text" id="name" class="required" value="<? echo $row_settings['Title']; ?>" size="50">
<span class="example">Your name or company name</span></td>
</tr>
<tr>
<td colspan="2">Authors<span class="example">(full address with ZIP)</span><br>
<textarea name="Authors" cols="40" rows="4" class="required" id="Authors"><? echo $row_settings['Authors']; ?></textarea>
</td>
</tr>
<tr>
<td>Year:</td>
<td><input name="Year" type="text" id="Year" value="<? echo $row_settings['Year']; ?>" ></td>
</tr>
<tr>
<td width="27%">Journal:</td>
<td width="73%"><input name="Journal" type="text" id="Journal" class="required" value="<? echo $row_settings['Journal']; ?>"></td>
</tr>
<tr>
<td>Link:</td>
<td><input name="Link" type="text" id="Link" value="<? echo $row_settings['Link']; ?>"></td>
</tr>
<tr>
<td>Website</td>
<td><input name="web" type="text" id="web" class="optional defaultInvalid url" value="<? echo $row_settings['website']; ?>">
<span class="example">Example: http://www.domain.com</span></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>

</tr>
<tr>

</tr>
</table>
<p align="center">
<input name="doSave" type="submit" id="doSave" value="Save">
</p>
</form>
<?php } ?>
<h3 class="titlehdr">Change Password</h3>
<p>If you want to change your password, please input your old and new password
to make changes.</p>
<form name="pform" id="pform" method="post" action="">


</p>
<p>&nbsp; </p>
</form>
<p>&nbsp; </p>
<p>&nbsp;</p>

<p align="right">&nbsp; </p></td>
<td width="196" valign="top">&nbsp;</td>
</tr>
<tr>
<td colspan="3">&nbsp;</td>
</tr>
</table>

</body>
</html>

smksmk
چهارشنبه 29 مرداد 1393, 12:44 عصر
کد صحیح :


<?php




include 'dbc.php';
page_protect();


$err = array();
$msg = array();


if($_POST['doUpdate'] == 'Update')
{




$rs_pwd = mysql_query("select Title from mytable where Title='titletext'");
list($old) = mysql_fetch_row($rs_pwd);
$old_salt = substr($old,0,9);






}


if($_POST['doSave'] == 'Save')
{
// Filter POST data for harmful code (sanitize)
foreach($_POST as $key => $value) {
$data[$key] = filter($value);
}




mysql_query("UPDATE mytable SET
`Title` = '".$data['Title']."',
`Authors` = '".$data['Authors']."',
`Year` = '".$data['Year']."',
`Journal` = '".$data['Journal']."',
`Link` = '".$data['Link']."',
WHERE Title='".$_SESSION['titletext']."'
") or die(mysql_error());


//header("Location: mysettings.php?msg=mytable Sucessfully Saved");
$msg[] = "mytable Sucessfully Saved";
}

$rs_settings = mysql_query("select * from mytable where Title='titletext'");
?>
<html>
<head>
<title>My Account Settings</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script language="JavaScript" type="text/javascript" src="js/jquery.validate.js"></script>
<script>
$(document).ready(function(){
$("#myform").validate();
$("#pform").validate();
});
</script>
<link href="styles.css" rel="stylesheet" type="text/css">
</head>


<body>
<table width="100%" border="0" cellspacing="0" cellpadding="5" class="main">
<tr>
<td colspan="3">&nbsp;</td>
</tr>
<tr>
<td width="160" valign="top"><?php
/*********************** MYACCOUNT MENU ****************************
This code shows my account menu only to logged in users.
Copy this code till END and place it in a new html or php where
you want to show myaccount options. This is only visible to logged in users
************************************************** *****************/
if (isset($_SESSION[titletext])) {?>
<div class="myaccount">
<p><strong>My Account</strong></p>
<a href="myaccount.php">My Account</a><br>
<a href="mysettings.php">Settings</a><br>
<a href="logout.php">Logout </a>
<p>You can add more links here for users</p></div>
<?php }
/*******************************END**************** **********/
?>
<?php
if (checkAdmin()) {
/*******************************END**************** **********/
?>
<p> <a href="admin.php">Admin CP </a></p>
<?php } ?>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p></td>
<td width="732" valign="top">
<h3 class="titlehdr">My Account - Settings</h3>
<p>
<?php
if(!empty($err)) {
echo "<div class=\"msg\">";
foreach ($err as $e) {
echo "* Error - $e <br>";
}
echo "</div>";
}
if(!empty($msg)) {
echo "<div class=\"msg\">" . $msg[0] . "</div>";


}
?>
</p>
<p>Here you can make changes to your profile. Please note that you will
not be able to change your email which has been already registered.</p>
<?php while ($row_settings = mysql_fetch_array($rs_settings)) {?>
<form action="mysettings.php" method="post" name="myform" id="myform">
<table width="90%" border="0" align="center" cellpadding="3" cellspacing="3" class="forms">
<tr>
<td colspan="2"> mytable Title:<br> <input name="name" type="text" id="name" class="required" value="<? echo $row_settings['Title']; ?>" size="50">
<span class="example">Your name or company name</span></td>
</tr>
<tr>
<td colspan="2">Authors<span class="example">(full address with ZIP)</span><br>
<textarea name="Authors" cols="40" rows="4" class="required" id="Authors"><? echo $row_settings['Authors']; ?></textarea>
</td>
</tr>
<tr>
<td>Year:</td>
<td><input name="Year" type="text" id="Year" value="<? echo $row_settings['Year']; ?>" ></td>
</tr>
<tr>
<td width="27%">Journal:</td>
<td width="73%"><input name="Journal" type="text" id="Journal" class="required" value="<? echo $row_settings['Journal']; ?>"></td>
</tr>
<tr>
<td>Link:</td>
<td><input name="Link" type="text" id="Link" value="<? echo $row_settings['Link']; ?>"></td>
</tr>
<tr>
<td>Website</td>
<td><input name="web" type="text" id="web" class="optional defaultInvalid url" value="<? echo $row_settings['website']; ?>">
<span class="example">Example: http://www.domain.com</span></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>

</tr>
<tr>

</tr>
</table>
<p align="center">
<input name="doSave" type="submit" id="doSave" value="Save">
</p>
</form>
<?php } ?>
<h3 class="titlehdr">Change Password</h3>
<p>If you want to change your password, please input your old and new password
to make changes.</p>
<form name="pform" id="pform" method="post" action="">



</p>
<p>&nbsp; </p>
</form>
<p>&nbsp; </p>
<p>&nbsp;</p>

<p align="right">&nbsp; </p></td>
<td width="196" valign="top">&nbsp;</td>
</tr>
<tr>
<td colspan="3">&nbsp;</td>
</tr>
</table>


</body>
</html>