0
ログインしたユーザーが連絡先情報を変更できるWebサイトを構築しようとしています。フォームを使用して編集可能なユーザー情報
私は情報を入力できるようになっていますが、ログアウトしてもう一度ログインすると、PHPmyadminのエントリがあるにもかかわらずフォームフィールドが再び空になります。
私は彼の電話番号を変更した、ユーザーのレコードを更新できるようにしたいと思います。
<?php require_once('Connections/user_settings.php'); ?>
<?php
//initialize the session
if (!isset($_SESSION)) {
session_start();
}
// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
$logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
//to fully log out a visitor we need to clear the session varialbles
$_SESSION['MM_Username'] = NULL;
$_SESSION['MM_UserGroup'] = NULL;
$_SESSION['PrevUrl'] = NULL;
unset($_SESSION['MM_Username']);
unset($_SESSION['MM_UserGroup']);
unset($_SESSION['PrevUrl']);
$logoutGoTo = "login.php";
if ($logoutGoTo) {
header("Location: $logoutGoTo");
exit;
}
}
?>
<?php
if (!isset($_SESSION)) {
session_start();
}
$MM_authorizedUsers = "Admin";
$MM_donotCheckaccess = "false";
// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {
// For security, start by assuming the visitor is NOT authorized.
$isValid = False;
// When a visitor has logged into this site, the Session variable MM_Username set equal to their username.
// Therefore, we know that a user is NOT logged in if that Session variable is blank.
if (!empty($UserName)) {
// Besides being logged in, you may restrict access to only certain users based on an ID established when they login.
// Parse the strings into arrays.
$arrUsers = Explode(",", $strUsers);
$arrGroups = Explode(",", $strGroups);
if (in_array($UserName, $arrUsers)) {
$isValid = true;
}
// Or, you may restrict access to only certain users based on their username.
if (in_array($UserGroup, $arrGroups)) {
$isValid = true;
}
if (($strUsers == "") && false) {
$isValid = true;
}
}
return $isValid;
}
$MM_restrictGoTo = "denied_access.html";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {
$MM_qsChar = "?";
$MM_referrer = $_SERVER['PHP_SELF'];
if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0)
$MM_referrer .= "?" . $_SERVER['QUERY_STRING'];
$MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
header("Location: ". $MM_restrictGoTo);
exit;
}
?>
<?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_update"])) && ($_POST["MM_update"] == "form")) {
$updateSQL = sprintf("UPDATE user_settings SET name=%s, phonenumber=%s, email=%s, country=%s, street1=%s, street2=%s, city=%s, `state`=%s, postalcode=%s WHERE userID=%s",
GetSQLValueString($_POST['settings_name'], "text"),
GetSQLValueString($_POST['settings_phonenumber'], "text"),
GetSQLValueString($_POST['settings_email'], "text"),
GetSQLValueString($_POST['settings_country'], "text"),
GetSQLValueString($_POST['settings_street1'], "text"),
GetSQLValueString($_POST['settings_street2'], "text"),
GetSQLValueString($_POST['settings_city'], "text"),
GetSQLValueString($_POST['settings_state'], "text"),
GetSQLValueString($_POST['settings_postalcode'], "text"),
GetSQLValueString($_POST['settings_userID'], "int"));
mysql_select_db($database_user_settings, $user_settings);
$Result1 = mysql_query($updateSQL, $user_settings) or die(mysql_error());
$updateGoTo = "index.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
mysql_select_db($database_user_settings, $user_settings);
$query_settings_recordset = "SELECT * FROM user_settings";
$settings_recordset = mysql_query($query_settings_recordset, $user_settings) or die(mysql_error());
$row_settings_recordset = mysql_fetch_assoc($settings_recordset);
$totalRows_settings_recordset = mysql_num_rows($settings_recordset);
?>
<!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>
<link href="Home.css" rel="stylesheet" type="text/css" />
</head>
<body><br />
<nav>
<ul class="nav">
<li><a href="index.php">HOME</a></li>
<li><a href="catalog.php">CATALOG</a></li>
<li><a href="reporting.php">REPORTING</a></li>
<li><a href="import_data.php">IMPORT DATA</a></li>
<li><a class="current" href="settings.php">SETTINGS</a></li>
<li><a href="<?php echo $logoutAction ?>">SIGN OUT</a><br />
</li></ul></nav>
<nav>
<ul class="nav2">
<li><a class="current" href="settings.php">Contact Detail </a></li> |
<li><a href="settings_payment.php">Payment Details</a></li>
</ul></li></div>
<div>
<h1>SETTINGS (Admin)</h1>
<strong>CONTACT DETAILS</strong>
<br />
<br /><form action="<?php echo $editFormAction; ?>" method="POST" name="form">
Name <input name="settings_userID" type="hidden" id="settings_userID" form="settings_contact_form" title="Settings UserID"><br />
<input name="settings_name" type="text" id="settings_name" form="settings_contact_form" title="Settings Name"><br />
Phone Number <br />
<input name="settings_phonenumber" type="text" id="settings_phonenumber" form="settings_contact_form" title="Settings Phonenumber"><br />
E-Mail<br />
<input name="settings_email" type="email" id="settings_email" form="setting_contacts_form" title="Settings Email"><br />
Country<br />
<select name="settings_country">
<option value="AU">Australia</option>
<option value="AT">Austria</option>
<option value="BE">Belgium</option>
<option value="CA">Canada</option>
<option value="DK">Denmark</option>
<option value="FR">France</option>
<option value="DE">Germany</option>
<option value="IT">Italy</option>
<option value="LU">Luxembourg</option>
<option value="NL">Netherlands</option>
<option value="NZ">New Zealand</option>
<option value="PT">Portugal</option>
<option value="ES">Spain</option>
<option value="SE">Sweden</option>
<option value="CH">Switzerland</option>
<option value="GB">United Kingdom</option>
<option value="US">United States</option>
</select><br />
Street Address 1<br />
<input name="settings_street1" type="text" id="settings_street1" form="settings_contact_form" title="Settings Street Adress 1"><br />
Street Address 2<br />
<input name="settings_street2" type="text" id="settings_street2" form="settings_contact_form" title="Settings Street Adress 2"><br />
Town/City<br />
<input name="settings_city" type="text" id="settings_city" form="settings_contact_form" title="Settings City"><br />
State<br />
<input name="settings_state" type="text" id="settings_state" form="settings_contact_form" title="Settings State"><br />
Postal code<br />
<input name="settings_postalcode" type="text" id="settings_postalcode" form="settinga_contact_form" title="Settings Postal Code"><br />
<br />
<input name="Save_button" type="submit" id="Save_button" title="Save" value=" SAVE "><br />
<input type="hidden" name="MM_update" value="form" />
</form><br />
<br />
</body>
</html>
<?php
mysql_free_result($settings_recordset);
?>
ログイン時にユーザーのIDを持っているVARを作成するあなたは、私があまりにもことを見た –
を更新するために、INSERTクエリを変更更新されない新しいデータを挿入しています一度私は更新クエリを何も変更しようとしました。一度ログインすると、フィールドはまだ空です。コードを新しい更新コードに置き換えました。 –
ユーザーIDが間違ってセッション取得されています –