简体   繁体   中英

Form not submitting Select options and I get a blank screen and no error in error log PHP/SQL

Hi I have a form that i am trying to insert into a database but when i fill it in it redirects to the action page where i am met with a blank screen and no error in my log.

None of my select options are inserting into the database, but all the other fields are?

This is my form I have removed all the classes to make it somewhat easier to read:

<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>

This is my submit code(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;

}
?>

Any Ideas?

do not use "name" tag with use with .. and also there is no value tag with all options, add values with all options...

your dropdown should be something like this

<select name="Department" >
<option value="1">1</option>
<option value="2">2</option>
</select>

and to avaid blank page redirect to some html page after query execution..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM