Joe*_*ook 0 php mysql forms session post
我正在使用Dreamweaver构建我的PHP/MySQL站点,因为我的技能相当小,我想将选项从多选项下拉列表保存到$_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);
?>
Run Code Online (Sandbox Code Playgroud)
这就是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>
Run Code Online (Sandbox Code Playgroud)
似乎没有选择只保存到$_SESSIONDreamweaver中的数据库而不是输入或更新数据库.每次我尝试创建记录集时,我在第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>
Run Code Online (Sandbox Code Playgroud)
根据本文顶部示例的输入,它可以正确地限制数据的工作方式.简而言之,我想将多选项下拉列表中的选项存储为$_SESSION['book']变量,以便我可以在下一页上使用它.有人可以帮助我找到正确的方法来实现这一目标吗?
不确定它有多大价值,但这里也是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);
?>
Run Code Online (Sandbox Code Playgroud)
编辑:我弄清楚为什么我在第114行得到错误,因为它是一个错误的支架,但仍然无法让它添加记录集,但是.
(我第一次阅读这篇文章时,我认为这是一个笑话.然后我瞥了一眼你的一些答案,我觉得你是SO coderot的牺牲品,你不能因此而受到指责.这太简单了谷歌以你的方式垃圾PHP.)
简而言之,我想将多选项下拉列表中的选项存储为$ _SESSION ['book']变量,以便我可以在下一页上使用它.有人可以帮助我找到正确的方法来实现这一目标吗?
当然.所以,首先:告诉一群程序员你正在使用Dreamweaver来编写PHP,因为你缺乏技能就像告诉一群猎人你正在追逐一只带有弹弓射击的熊,因为你不知道如何射击枪:期待很多关于射击枪或猎兔的建议,但不要指望弹弓有太多帮助.
tl;博士:Dreamweaver没有帮助你.这是你为获得答案而苦苦挣扎的部分原因.
...还有这个?
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
Run Code Online (Sandbox Code Playgroud)只是fyi,这是你在添加记录集方面遇到麻烦的最大原因,因为这种方法在十多年内并不合理.至少使用实际支持的东西.
希望能让你指出正确的方向.如果您需要更多帮助,我就在附近.