- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 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 没有帮助您。这是您为获得答案而苦苦挣扎的部分原因。
...还有这个?
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
仅供引用,这是您在添加记录集时遇到困难的最大原因,因为这种方法在十多年来一直不合理。至少use something actually supported .
希望这能让您指明正确的方向。如果您需要更多帮助,我就在身边。
关于php - 如何在 Dreamweaver 中不更新数据库的情况下将 PHP 表单数据保存到 session 变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30543788/
我有一台 MySQL 服务器和一台 PostgreSQL 服务器。 需要从多个表中复制或重新插入一组数据 MySQL 流式传输/同步到 PostgreSQL 表。 这种复制可以基于时间(Sync)或事
如果两个表的 id 彼此相等,我尝试从一个表中获取数据。这是我使用的代码: SELECT id_to , email_to , name_to , status_to
我有一个 Excel 工作表。顶行对应于列名称,而连续的行每行代表一个条目。 如何将此 Excel 工作表转换为 SQL 表? 我使用的是 SQL Server 2005。 最佳答案 这取决于您使用哪
我想合并两个 Django 模型并创建一个模型。让我们假设我有第一个表表 A,其中包含一些列和数据。 Table A -------------- col1 col2 col3 col
我有两个表:table1,table2,如下所示 table1: id name 1 tamil 2 english 3 maths 4 science table2: p
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 1 年前。 Improve th
下面两个语句有什么区别? newTable = orginalTable 或 newTable.data(originalTable) 我怀疑 .data() 方法具有性能优势,因为它在标准 AX 中
我有一个表,我没有在其中显式定义主键,它并不是真正需要的功能......但是一位同事建议我添加一个列作为唯一主键以随着数据库的增长提高性能...... 谁能解释一下这是如何提高性能的? 没有使用索引(
如何将表“产品”中的产品记录与其不同表“图像”中的图像相关联? 我正在对产品 ID 使用自动增量。 我觉得不可能进行关联,因为产品 ID 是自动递增的,因此在插入期间不可用! 如何插入新产品,获取产品
我有一个 sql 表,其中包含关键字和出现次数,如下所示(尽管出现次数并不重要): ____________ dog | 3 | ____________ rat | 7 | ____
是否可以使用目标表中的LAST_INSERT_ID更新源表? INSERT INTO `target` SELECT `a`, `b` FROM `source` 目标表有一个自动增量键id,我想将其
我正在重建一个搜索查询,因为它在“我看到的”中变得多余,我想知道什么 (albums_artists, artists) ( ) does in join? is it for boosting pe
以下是我使用 mysqldump 备份数据库的开关: /usr/bin/mysqldump -u **** --password=**** --single-transaction --databas
我试图获取 MySQL 表中的所有行并将它们放入 HTML 表中: Exam ID Status Assigned Examiner
如何查询名为 photos 的表中的所有记录,并知道当前用户使用单个查询将哪些结果照片添加为书签? 这是我的表格: -- -- Table structure for table `photos` -
我的网站都在 InnoDB 表上运行,目前为止运行良好。现在我想知道在我的网站上实时发生了什么,所以我将每个页面浏览量(页面、引荐来源网址、IP、主机名等)存储在 InnoDB 表中。每秒大约有 10
我在想我会为 mysql 准备两个表。一个用于存储登录信息,另一个用于存储送货地址。这是传统方式还是所有内容都存储在一张表中? 对于两个表...有没有办法自动将表 A 的列复制到表 B,以便我可以引用
我不是程序员,我从这个表格中阅读了很多关于如何解决我的问题的内容,但我的搜索效果不好 我有两张 table 表 1:成员 id*| name | surname -------------------
我知道如何在 ASP.NET 中显示真实表,例如 public ActionResult Index() { var s = db.StaffInfoDBSet.ToList(); r
我正在尝试运行以下查询: "insert into visits set source = 'http://google.com' and country = 'en' and ref = '1234
我是一名优秀的程序员,十分优秀!