gpt4 book ai didi

php - SESSION 变量值未传递

转载 作者:搜寻专家 更新时间:2023-10-31 20:55:07 25 4
gpt4 key购买 nike

我正在尝试从 HTML 表单上的选择输入控件传递一个值。当我对它进行硬编码时,它会得到回应,如果没有,我得到的只是:发明类型没有正确通过。

这是我的 page1.php:

<?php
session_start();

$_SESSION['invtype'] = $invtype;

$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];

if (isset($_POST['Submit'])) {

if ($_POST['firstname'] != "") {
$_POST['firstname'] = filter_var($_POST['firstname'], FILTER_SANITIZE_STRING);
if ($_POST['firstname'] == "") {
$errors .= 'Please enter a valid first name.<br/><br/>';
}
} else {
$errors .= 'Please enter your first name.<br/>';
}

if ($_POST['lastname'] != "") {
$_POST['lastname'] = filter_var($_POST['lastname'], FILTER_SANITIZE_STRING);
if ($_POST['lastname'] == "") {
$errors .= 'Please enter a valid last name.<br/><br/>';
}
} else {
$errors .= 'Please enter your last name.<br/>';
}

if (!$errors) {header("location: offerform_switch.php");
}


else {
echo '<div style="color: red">' . $errors . '<br/>
</div>';



}
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Offer Form, Part 1</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" href="inventron_sage_short.css" type="text/css" />
<link rel="stylesheet" href="form.css" type="text/css" />

</head>
<body>
<div id = "logo">
<img src = "img/top.jpg" alt = "logo" />
</div>
<div id = "wrapper">




<div id="stylized" class="myform">
<form id="form" action="page1.php" method="post">



<p>
<label for="firstname">FIRST NAME*:
</label>
<input type="text" name="firstname" id="firstname" value="<?php echo $firstname?>" />
</p>

<p>
<label for="lastname">LAST NAME*:
</label>
<input type="text" name="lastname" id="lastname" value="<?php echo $lastname?>" />
</p>

<div id = "category">Categorize your invention:</div>

<div class="spacer"></div>

<p>
<select id="invtype" name="invtype">
<option value="0" selected="selected">Select type</option>
<option value="product">PRODUCT</option>
<option value="software">SOFTWARE</option>

</select>
<input type="submit" name="Submit" value="Next!" />

</div>
</div>
</body>
</html>

这是我的 offerform_switch.php:

<?php

session_start();
// echo variable from the session, we set this on our other page
echo $_SESSION['invtype'];
$invtype = $_SESSION['invtype'];

//connect to your database ** EDIT REQUIRED HERE **
mysql_connect("mysql.myserver.com","myuser","mypassword"); //(host, username, password)

//specify database ** EDIT REQUIRED HERE **
mysql_select_db("invention") or die("Unable to select database"); //select which database we're using


switch ($invtype){
case "product":
include("page2_product.php");
break;
case "software":
include("page2_software.php");
break;
default:
echo "The invention type did not go through correctly.";
}

?>

我做错了什么?

谢谢!

最佳答案

应该是

$_SESSION['invtype'] = $_POST['invtype'];

关于php - SESSION 变量值未传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3535195/

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