gpt4 book ai didi

php - 如何在 Dreamweaver 中不更新数据库的情况下将 PHP 表单数据保存到 session 变量?

转载 作者:行者123 更新时间:2023-12-01 00:20:23 26 4
gpt4 key购买 nike

我正在使用 Dreamweaver 构建我的 PHP/MySQL 站点,因为我的技能相当低,而且我想将多个选项下拉列表中的选择保存到 $_SESSION 变量中。在使用上一页中的以下内容更新数据库中的字段时,我已经成功地保存到 session 变量并且似乎正在工作(Dreamweaver 插入的页面顶部,我评论了我编辑它的位置以使其存储到$_SESSION):

<?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']);
}
/// this is what to edit to make session variables from a form
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "SelectBookForm")) {
$insertSQL = sprintf("INSERT INTO characters (character_name1, play_system, character_owner) VALUES (%s, %s, %s)",
GetSQLValueString($_POST['NewCharacterNameInput'], "text"),
GetSQLValueString($_POST['select'], "text"),
GetSQLValueString($_POST['CharacterOwner'], "int"));
$_SESSION['play_system'] = GetSQLValueString($_POST['select'], "text");
$_SESSION['character_owner'] = GetSQLValueString($_POST['CharacterOwner'], "int");
$_SESSION['character_name1'] = GetSQLValueString($_POST['NewCharacterNameInput'], "text");

mysql_select_db($database_DLP_RPG, $DLP_RPG);
$Result1 = mysql_query($insertSQL, $DLP_RPG) or die(mysql_error());

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

mysql_select_db($database_DLP_RPG, $DLP_RPG);
$query_login = "SELECT * FROM users";
$login = mysql_query($query_login, $DLP_RPG) or die(mysql_error());
$row_login = mysql_fetch_assoc($login);
$totalRows_login = mysql_num_rows($login);

mysql_select_db($database_DLP_RPG, $DLP_RPG);
$query_play_systems_recordset = "SELECT * FROM play_systems";
$play_systems_recordset = mysql_query($query_play_systems_recordset, $DLP_RPG) or die(mysql_error());
$row_play_systems_recordset = mysql_fetch_assoc($play_systems_recordset);
$totalRows_play_systems_recordset = mysql_num_rows($play_systems_recordset);

mysql_select_db($database_DLP_RPG, $DLP_RPG);
$query_CharacterOwner = "SELECT * FROM users WHERE users.user_id =
(SELECT user_id FROM users WHERE user_login = '{$_SESSION['MM_Username']}')";
$CharacterOwner = mysql_query($query_CharacterOwner, $DLP_RPG) or die(mysql_error());
$row_CharacterOwner = mysql_fetch_assoc($CharacterOwner);
$totalRows_CharacterOwner = mysql_num_rows($CharacterOwner);
?>

这就是 Dreamweaver 用来在页面正文中制作表单的方法(同样,这是有效的方法):

<form action="<?php echo $editFormAction; ?>" name="SelectBookForm" method="POST" id="SelectBookForm"> 
<select name="select" size="1" form="SelectBookForm">
<?php
do {
?>
<option value="<?php echo $row_play_systems_recordset['play_system']?>"><?php echo $row_play_systems_recordset['play_system']?></option>
<?php
} while ($row_play_systems_recordset = mysql_fetch_assoc($play_systems_recordset));
$rows = mysql_num_rows($play_systems_recordset);
if($rows > 0) {
mysql_data_seek($play_systems_recordset, 0);
$row_play_systems_recordset = mysql_fetch_assoc($play_systems_recordset);
}
?>
</select>
<input name="CharacterOwner" type="hidden" id="CharacterOwner" value="<?php echo $row_CharacterOwner['user_id']; ?>"><input name="NewCharacterNameInput" type="text" required id="NewCharacterNameInput" form="SelectBookForm" placeholder="Give your character a name!" size="25" maxlength="128">
<BR>
<input name="NewCharacterSubmit" type="submit" id="NewCharacterSubmit" form="SelectBookForm" value="Select system and start my character">

<input type="hidden" name="MM_insert" value="PlaySystemForm">
<input type="hidden" name="MM_insert" value="SelectBookForm">
</form>

在 Dreamweaver 中似乎没有仅保存到 $_SESSION 而不是输入或更新到数据库的选项。每次我尝试创建记录集时,我都会在第 114 行收到错误,这只是两个 } 括号之间的空格。

这是我要创建的页面的形式:

<form method="post" id="BookSelectionForm">
<select name="BookSelections" size="10" multiple id="BookSelections" form="BookSelectionForm">
<?php
do {
?>
<option value="<?php echo $row_BooksRecordset['book']?>"><?php echo $row_BooksRecordset['book']?></option>
<?php
} while ($row_BooksRecordset = mysql_fetch_assoc($BooksRecordset));
$rows = mysql_num_rows($BooksRecordset);
if($rows > 0) {
mysql_data_seek($BooksRecordset, 0);
$row_BooksRecordset = mysql_fetch_assoc($BooksRecordset);
}
?>
</select>

<input name="BookSelectionFormSubmitButton" type="submit" id="BookSelectionFormSubmitButton" form="BookSelectionForm" formmethod="POST" value="Select these campaigns">
</form>

它可以正常工作,并根据本文顶部示例中的输入准确地限制数据。长话短说,我想将多选项下拉列表中的选择存储为 $_SESSION['book'] 变量,以便我可以在下一页上使用它。有人可以帮助我走上正确的道路来实现这一目标吗?

不确定它有多少值(value),但这里也是 Dreamweaver 允许且没有错误的页面顶部记录集信息。

<?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;
}


}

mysql_select_db($database_DLP_RPG, $DLP_RPG);
$query_login = "SELECT * FROM users";
$login = mysql_query($query_login, $DLP_RPG) or die(mysql_error());
$row_login = mysql_fetch_assoc($login);
$totalRows_login = mysql_num_rows($login);

/// this one sets the play_system to the one selected at the beginning and can be used to restrict results by using the variable $BooksRecordset, I probably need to change this because it's confusing. It's giving the play_system and not the books. Maybe RealBooksRecordset is better for now.
mysql_select_db($database_DLP_RPG, $DLP_RPG);
$query_BooksRecordset = "SELECT * FROM character_system WHERE character_system.system_name = ({$_SESSION['play_system']})";
$BooksRecordset = mysql_query($query_BooksRecordset, $DLP_RPG) or die(mysql_error());
$row_BooksRecordset = mysql_fetch_assoc($BooksRecordset);
$totalRows_BooksRecordset = mysql_num_rows($BooksRecordset);



?>

编辑:我弄清楚了为什么我在第 114 行收到错误,因为它是一个错误的括号,但仍然无法添加记录集。

最佳答案

(我第一次读这篇文章时,我以为这是个玩笑。然后我浏览了一些你的回答,我觉得你是 SO coderot 的受害者,为此你这不能被指责。用谷歌搜索关于 PHP 的垃圾信息太容易了。)

Long story short, I want to store the selections from the multiple option drop-down list as a $_SESSION['book'] variable so I can use it on the next page. Can someone help put me on the correct course to achieve this?

当然。所以,首先:告诉一群程序员你正在使用 Dreamweaver 编写 PHP 因为你缺乏技能就像告诉一群猎人你正在用弹弓追熊因为你不知道如何开枪:期待很多关于开枪或打兔子的建议,但不要指望在弹弓方面有太多帮助。

tl;dr:Dreamweaver 没有帮助您。这是您为获得答案而苦苦挣扎的部分原因。

ಠ_ಠ

仅供引用,这是您在添加记录集时遇到困难的最大原因,因为这种方法在十多年来一直不合理。至少use something actually supported .

希望这能让您指明正确的方向。如果您需要更多帮助,我就在身边。

关于php - 如何在 Dreamweaver 中不更新数据库的情况下将 PHP 表单数据保存到 session 变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30543788/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com