表单未提交 Select 选项,我得到一个空白屏幕并且错误日志中没有错误 PHP/SQL
Form not submitting Select options and I get a blank screen and no error in error log PHP/SQL
您好,我有一个表格,我正试图将其插入数据库,但是当我填写它时,它会重定向到操作页面,在那里我遇到了一个空白屏幕,并且我的日志中没有错误。
我的 select 选项中的 None 正在插入到数据库中,但所有其他字段都是?
这是我的表格,我删除了所有 类 以使其更易于阅读:
<form action="ticket-submit.php" method="post">
<div>
<label>Department<span class="required">*</span></label>
<div>
<select required>
<option value="">Choose option</option>
<option name="Department">1</option>
<option name="Department">2</option>
<option name="Department">3</option>
</select>
</div>
</div>
<?php
$getTicketCategory = "SELECT * FROM po_ticket_category";
$queryTicketCategory = sqlsrv_query($sapconn2, $getTicketCategory);
?>
<div>
<label>Categorys<span class="required">*</span></label>
<div>
<select required>
<option value="">Choose option</option>
<?php while($ticketCategory = sqlsrv_fetch_array($queryTicketCategory, SQLSRV_FETCH_ASSOC)) : ?>
<option name="Category"><?php echo $ticketCategory['Category']; ?></option>
<?php endwhile; ?>
</select>
</div>
</div>
<?php
$getTicketPriority = "SELECT * FROM po_ticket_priority";
$queryTicketPriority = sqlsrv_query($sapconn2, $getTicketPriority);
?>
<div>
<label>Priority<span class="required">*</span></label>
<div>
<select required>
<option value="">Choose option</option>
<?php while($ticketPriority = sqlsrv_fetch_array($queryTicketPriority, SQLSRV_FETCH_ASSOC)) : ?>
<option name="PriorityLevel"><?php echo $ticketPriority['PriorityLevel']; ?></option>
<?php endwhile; ?>
</select>
</div>
</div>
<div>
<label for="Subject">Subject<span class="required">*</span></label>
<div>
<input type="text" name="Subject" id="Subject" placeholder="Subject" required>
</div>
</div>
<div>
<label for="Description">Description<span class="required">*</span></label>
<div>
<textarea name="Description" id="Description" rows="3" placeholder='Whats your issue...' required></textarea>
</div>
</div>
<div>
<div>
<button type="submit" id="submit" name="submit" value="1">Submit Ticket</button>
</div>
</div>
</form>
这是我的提交代码(ticket-submit.php):
<?php
if(isset($_POST['submit'])){
$userName = (isset($user['userName']) && !empty($user['userName']))?$user['userName'] : NULL;
$department = (isset($_POST['Department']) && !empty($_POST['Department']))?$_POST['Department'] : NULL;
$category = (isset($_POST['Category']) && !empty($_POST['Category']))?$_POST['Category'] : NULL;
$priority = (isset($_POST['PriorityLevel']) && !empty($_POST['PriorityLevel']))?$_POST['PriorityLevel'] : NULL;
$subject = (isset($_POST['Subject']) && !empty($_POST['Subject']))?$_POST['Subject'] : NULL;
$description = (isset($_POST['Description']) && !empty($_POST['Description']))?$_POST['Description'] : NULL;
$query = "INSERT INTO po_ticket_ticket (UserName, DepartmentID, Category, PriorityLevel, Subject, Description, TicketCreated)
VALUES ('$userName', '$department','$category', '$priority', '$subject', '$description', CURRENT_TIMESTAMP)
";
$stmt = sqlsrv_prepare($sapconn2, $query);
sqlsrv_execute($stmt);
return $stmt;
}
?>
有什么想法吗?
不要将 "name" 标签与 .. 一起使用,并且所有选项都没有值标签,添加所有选项的值...
你的下拉菜单应该是这样的
<select name="Department" >
<option value="1">1</option>
<option value="2">2</option>
</select>
并避免空白页面在查询执行后重定向到某些 html 页面..
您好,我有一个表格,我正试图将其插入数据库,但是当我填写它时,它会重定向到操作页面,在那里我遇到了一个空白屏幕,并且我的日志中没有错误。
我的 select 选项中的None 正在插入到数据库中,但所有其他字段都是?
这是我的表格,我删除了所有 类 以使其更易于阅读:
<form action="ticket-submit.php" method="post">
<div>
<label>Department<span class="required">*</span></label>
<div>
<select required>
<option value="">Choose option</option>
<option name="Department">1</option>
<option name="Department">2</option>
<option name="Department">3</option>
</select>
</div>
</div>
<?php
$getTicketCategory = "SELECT * FROM po_ticket_category";
$queryTicketCategory = sqlsrv_query($sapconn2, $getTicketCategory);
?>
<div>
<label>Categorys<span class="required">*</span></label>
<div>
<select required>
<option value="">Choose option</option>
<?php while($ticketCategory = sqlsrv_fetch_array($queryTicketCategory, SQLSRV_FETCH_ASSOC)) : ?>
<option name="Category"><?php echo $ticketCategory['Category']; ?></option>
<?php endwhile; ?>
</select>
</div>
</div>
<?php
$getTicketPriority = "SELECT * FROM po_ticket_priority";
$queryTicketPriority = sqlsrv_query($sapconn2, $getTicketPriority);
?>
<div>
<label>Priority<span class="required">*</span></label>
<div>
<select required>
<option value="">Choose option</option>
<?php while($ticketPriority = sqlsrv_fetch_array($queryTicketPriority, SQLSRV_FETCH_ASSOC)) : ?>
<option name="PriorityLevel"><?php echo $ticketPriority['PriorityLevel']; ?></option>
<?php endwhile; ?>
</select>
</div>
</div>
<div>
<label for="Subject">Subject<span class="required">*</span></label>
<div>
<input type="text" name="Subject" id="Subject" placeholder="Subject" required>
</div>
</div>
<div>
<label for="Description">Description<span class="required">*</span></label>
<div>
<textarea name="Description" id="Description" rows="3" placeholder='Whats your issue...' required></textarea>
</div>
</div>
<div>
<div>
<button type="submit" id="submit" name="submit" value="1">Submit Ticket</button>
</div>
</div>
</form>
这是我的提交代码(ticket-submit.php):
<?php
if(isset($_POST['submit'])){
$userName = (isset($user['userName']) && !empty($user['userName']))?$user['userName'] : NULL;
$department = (isset($_POST['Department']) && !empty($_POST['Department']))?$_POST['Department'] : NULL;
$category = (isset($_POST['Category']) && !empty($_POST['Category']))?$_POST['Category'] : NULL;
$priority = (isset($_POST['PriorityLevel']) && !empty($_POST['PriorityLevel']))?$_POST['PriorityLevel'] : NULL;
$subject = (isset($_POST['Subject']) && !empty($_POST['Subject']))?$_POST['Subject'] : NULL;
$description = (isset($_POST['Description']) && !empty($_POST['Description']))?$_POST['Description'] : NULL;
$query = "INSERT INTO po_ticket_ticket (UserName, DepartmentID, Category, PriorityLevel, Subject, Description, TicketCreated)
VALUES ('$userName', '$department','$category', '$priority', '$subject', '$description', CURRENT_TIMESTAMP)
";
$stmt = sqlsrv_prepare($sapconn2, $query);
sqlsrv_execute($stmt);
return $stmt;
}
?>
有什么想法吗?
不要将 "name" 标签与 .. 一起使用,并且所有选项都没有值标签,添加所有选项的值...
你的下拉菜单应该是这样的
<select name="Department" >
<option value="1">1</option>
<option value="2">2</option>
</select>
并避免空白页面在查询执行后重定向到某些 html 页面..