PDA

View Full Version : مشکل در به روز رسانی اطلاعات



omidparkour
جمعه 13 اردیبهشت 1392, 19:41 عصر
سلام
من تازه شروع کردم و دارم php یاد میگیرم و داشتم با دریم ویور اطلاعات رو از طریق فرم وارد و به روز رسانی میکردم که در به روز رسانی مشکل دارم این هم کد هام لطفا راهنمایی کنید چگونه این عمل رو انجام بدم
کد فرم به روز رسانی:


<?php require_once('Connections/connect.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO i (code, name, fname) VALUES (%s, %s, %s)",
GetSQLValueString($_POST['code'], "int"),
GetSQLValueString($_POST['name'], "text"),
GetSQLValueString($_POST['fname'], "text"));

mysql_select_db($database_connect, $connect);
$Result1 = mysql_query($insertSQL, $connect) or die(mysql_error());

$insertGoTo = "Untitled-1.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}

if ((isset($_GET['code'])) && ($_GET['code'] != "")) {
$deleteSQL = sprintf("DELETE FROM i WHERE code=%s",
GetSQLValueString($_GET['code'], "int"));

mysql_select_db($database_connect, $connect);
$Result1 = mysql_query($deleteSQL, $connect) or die(mysql_error());

$deleteGoTo = "Untitled-1.php";
if (isset($_SERVER['QUERY_STRING'])) {
$deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
$deleteGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $deleteGoTo));
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
$updateSQL = sprintf("UPDATE i SET fname=%s WHERE name=%s",
GetSQLValueString($_POST['fname'], "text"),
GetSQLValueString($_POST['name'], "text"));

mysql_select_db($database_connect, $connect);
$Result1 = mysql_query($updateSQL, $connect) or die(mysql_error());

$updateGoTo = "Untitled-1.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
$updateSQL = sprintf("UPDATE i SET name=%s, fname=%s WHERE code=%s",
GetSQLValueString($_POST['name'], "text"),
GetSQLValueString($_POST['fname'], "text"),
GetSQLValueString($_POST['code'], "int"));

mysql_select_db($database_connect, $connect);
$Result1 = mysql_query($updateSQL, $connect) or die(mysql_error());

$updateGoTo = "Untitled-1.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}

$colname_Recordset1 = "-1";
if (isset($_GET['a'])) {
$colname_Recordset1 = $_GET['a'];
}
mysql_select_db($database_connect, $connect);
$query_Recordset1 = sprintf("SELECT * FROM i WHERE code = %s", GetSQLValueString($colname_Recordset1, "int"));
$Recordset1 = mysql_query($query_Recordset1, $connect) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

mysql_select_db($database_connect, $connect);
$query_Recordset2 = "SELECT * FROM i";
$Recordset2 = mysql_query($query_Recordset2, $connect) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 = mysql_num_rows($Recordset2);
?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>">
<p>&nbsp;</p>
<p>
<label>نام</label>
<input type="text" name="name" id="name" />
</p>
<p>
<label>نام خانوادگی
<input type="text" name="fname" id="fname" />
</label>
</p>
<p>
<label>
<input type="submit" name="add" id="add" value="add" />
</label>

</p>
<input type="hidden" name="MM_insert" value="form1" />
<input type="hidden" name="MM_update" value="<?php echo $row_Recordset1['code']; ?>" />
</form>
<form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>">
<label>
<input type="submit" name="update" id="update" value="update" />
</label>
</form>
</body>
</html>
<?php
mysql_free_result($Recordset1);

mysql_free_result($Recordset2);
?>





این هم کد نمایش اطلاعات:


<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_connect = "localhost";
$database_connect = "testnew";
$username_connect = "root";
$password_connect = "";
$connect = mysql_pconnect($hostname_connect, $username_connect, $password_connect) or trigger_error(mysql_error(),E_USER_ERROR);
?>



لطفا راهنمایی کنید