我有两步表格。 create.php和create2.php。两个页面都是表格。填好第一个表格后,用户按下"继续"并进入第二种形式,我传递并将第一种形式的值存储在隐藏的输入中。在填写并提交第二个表单后,我想要弹出窗口,这意味着成功提交表单并将所有数据插入数据库。似乎一切都运行良好,所有数据都在数据库中,但是我没有弹出窗口,我得到的是关于我的隐藏输入的未定义索引警告。
好的,这是create.php的代码:
<form class="formcss" method="post" action="create2.php" id="reportform" enctype="multipart/form-data">
<fieldset style="background-color:white;">
<legend style="font-size: 20px;">New Project</legend>
<br>
<div class="row">
<div class="small-8 large-8 columns">
<label>Project Code: <small style="color:red;">*</small>
<input type="text" name="code" maxlength="155" id="code" class="input input1 name" onkeyup="limitTextCount('code', 'divcount0', 155, 0);" onkeydown="limitTextCount('code', 'divcount0', 155, 0);" <?php if (isset($code)) echo 'value="'.$code.'"' ?>/>
<label class="tool tool1" for="name" style="margin-top:-8px;">Code of the project</br>e.g. ASD001</label>
</label>
</div>
</div>
<div class="row">
<div class="small-8 large-8 columns">
<label>Project Name: <small style="color:red;">*</small>
<input type="text" name="title" maxlength="155" id="title" class="input input1 name" onkeyup="limitTextCount('title', 'divcount0', 155, 0);" onkeydown="limitTextCount('title', 'divcount0', 155, 0);" <?php if (isset($title)) echo 'value="'.$title.'"' ?>/>
<label class="tool tool1" for="name" style="margin-top:-8px;">Title of the project</br>e.g. Leon</label>
</label>
</div>
</div>
<div class="row">
<div class="small-8 large-8 columns">
<label>Process
<div class="multiselect">
<div class="selectBox">
<select onclick="showCheckboxes()" class="input input1 name">
<option>-- Select an option --</option>
</select>
<div class="overSelect"></div>
</div>
<div class="scrollable" id="checkboxes">
<?php
while ($row = mysql_fetch_array($result))
{
$row[0] = cleanOutputData($row[0]);
?>
<div class="row">
<div class="small-12 large-12 columns">
<label style="height: 37px; width:80%; float:left;">
<input type="checkbox" class="checkbox" style="margin-left:5%; width:15%;" name="process[]" id=<?php echo $row[0] ?> value=<?php echo $row[0]?> /><?php echo $row[0] ?>
</label>
<label style="width:40%; margin-left:60%;"><input type="text" class="field" disabled style="width:40%;" name="numberpl[]" id=<?php echo $row[0] ?> />
</label>
</div>
</div>
<?php
}
mysql_free_result($result);
?>
</div>
</div>
</label>
</div>
</div>
<div class="row">
<div class="small-8 large-8 columns">
<label>Comments
<textarea style="resize:none;" class="input input1 name" name="remark" rows="8" cols="50" maxlength="255" id="remark" onkeyup="limitTextCount('remark', 'divcount5', 255, 0);" onkeydown="limitTextCount('remark', 'divcount5', 255, 0);"><?php if (isset($remark)) echo $remark ?></textarea>
<label class="tool tool1" for="name" style="left:-140px;">Further comments</label>
</label>
</div>
<div class="small-6 large-6 columns">
<label> <?php if (isset($remark)){ echo "<label id='divcount5'></label>"; echo "<script>limitTextCount('remark', 'divcount5', 255, 0);</script>";} else echo "<label id='divcount5'>255 characters remaining</label>";?></label>
</div>
</div>
<div class="row">
<div class="small-8 large-8 columns">
<input type = "submit" name ="submit" style="margin-left:600px; width:150px;" class="button" onclick="userSubmitted = true;" value = "Continue"/>
</div>
</div>
<br/><br/>
</fieldset>
</form>
对于第二种形式create2.php:
<?php
session_start();
//if user haven't sign in will redirect user to login page
if(empty($_SESSION['login_user'])){
session_destroy();
header("Location: login.php");
}
$proc = isset($_POST['process'])?$_POST['process']:'';
//$proc=$_POST['process'];
$len = count($proc); // getting length of ur array that u need to condition ur loop
$num = isset($_POST['numberpl'])?$_POST['numberpl']:'';
//$num=$_POST['numberpl'];
//$len2 = count($num); // getting length of ur array that u need to condition ur loop
include 'verification/verify_form_details2.php';
require_once('inc/config.php');
//include 'verification/verify_form_details.php';
ob_start();
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "pp";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
?>
<form class="formcss" method="POST" name="checkoutForm" action="create2.php#err" id="reportform" enctype="multipart/form-data">
<?php
$res = verifyFormFields();
?>
<!-- hidden inputs from first form(create.php) -->
<input type="hidden" name="holdcode" value="<?php echo isset($_POST['code'])?$_POST['code']:'';?>">
<input type="hidden" name="holdtitle" value="<?php echo isset($_POST['title'])?$_POST['title']:'';?>">
<?php
//an array of inputs
for($y=0;$y<$len;$y++)
{
?>
<input type='hidden' name='holdprocess[]' value="<?php echo $proc[$y]?>">
<input type='hidden' name='holdnumber[]' value="<?php echo $num[$y]?>">
<?php
}
?>
<!-- hidden inputs from first form(create.php) -->
<br>
<fieldset style="background-color:white;">
<legend style="font-size: 20px;">Add Stuff</legend>
<br><br><br>
<div class="small-3 large-3 columns">
<label>Choose username</label>
<input placeholder="Search Me" id="box" type="text" />
<div id="myAccordion">
<?php for($i=321; $i<347; $i++)
{
echo "<h3>".chr($i)."</h3>";
echo '<ul class="source">';
$sql = "SELECT username FROM user WHERE username LIKE '".chr($i+32)."%' ";
$result = $conn->query($sql);
if ($result->num_rows > 0)
{
// output data of each row
while($row = $result->fetch_assoc())
{
$name= $row["username"];
echo"<li>". $name ."</li>";
}
} else
{
echo "0 results";
}
echo '</ul>';
}
?>
</div>
</div>
<div id="project" class="small-9 large-9 columns">
<label style="font-size: 40px; margin-left:10%;">Project <?php echo isset($_POST['code'])?$_POST['code']:''; ?></label>
<div class="rowone">
<div id="leader">
<label>Leader:</label>
<div class="ui-widget-content">
<div id="projLeader">
<ol>
<li class="placeholder" name="leader" <?php if (isset($leader)) echo 'value="'.$leader.'"' ?>>Add leader here</li>
<input type="hidden" name="leader" id="hiddenListInput1" />
</ol>
</div>
</div>
</div>
<div id="checker">
<label>Checker:</label>
<div class="ui-widget-content">
<div id="projChecker">
<ol>
<li class="placeholder" name="checker" <?php if (isset($checker)) echo 'value="'.$checker.'"' ?>>Add checker here</li>
<input type="hidden" name="checker" id="hiddenListInput2" />
</ol>
</div>
</div>
</div>
<div id="info">
<label>Information:</label>
<div class="ui-widget-content">
<ol>
<li>Total:</li>
<li>Total:</li>
<li>Total:</li>
<li>Total:</li>
<li>Total:</li>
</ol>
</div>
</div>
</div>
<div class="row">
<input type = "submit" id="savebutton" style="margin-left:300px; width:150px;" name ="submit" class="button" value = "Create Project" onclick="userSubmitted = true;" />
</div>
</div>
<div id="formModal" class="reveal-modal small" data-reveal aria-labelledby="modalTitle" aria-hidden="true" role="dialog" data-options="close_on_background_click:false">
<h2 id="modalTitle">Success!</h2>
<div style="font-weight: 400;font-size: 1.5em; font-family: 'Raleway', Arial, sans-serif;">Your Accident Report was Successfully Submitted!</div>
<div class="right">
<a href="#" id="closebtn" onclick="popUpNo()" class="button">Ok</a>
</div>
</div>
<?php
if($counta==1)
{
if($res=="")
{
$testing = JSON_encode($_SESSION['role']);
echo '<script>userSubmitted = true;</script>';
insertRecord();
echo "<script type ='text/javascript'>callShowAlert();</script>";
}
else{
echo "
<br><br><a style='color:red';>
$res
</a>
";
}
}
?>
<script>var testing = JSON.parse('<?= $testing; ?>');</script>
</fieldset>
</form>
以下是我提交第二份表格后的内容:
注意:
未定义的索引:C:\ xampp \ htdocs \ Projects \ 1ver \ create2.php中的进程 第9行
注意:
未定义索引:C:\ xampp \ htdocs \ Projects \ 1ver \ create2.php中的numberpl 在第12行
注意:
未定义索引:代码输入 C:\ xampp \ htdocs \ Projects \ 1ver \ create2.php 在行 256
通知:
未定义的索引:标题 257 C:\ xampp \ htdocs \ Projects \ 1ver \ create2.php
通知:
未定义的索引:C:\ xampp \ htdocs \ Projects \ 1ver \ create2.php中的标题 第302行
我正在使用另一个php页面将数据插入数据库。我只是没有得到可能成为问题的东西。谢谢你的帮助
答案 0 :(得分:0)
由于POST数组第一次不可用。因此,您收到此错误。如果您确实需要使用这些post变量,则应在这种情况下应用条件以避免这些错误。
我在这里添加一个,你可以做同样的事情。
试试这个:
<?php echo isset($_POST['code'])?$_POST['code']:''; ?>