丢失的PHP变量,最后一次出现在Chrome中,与$quote\u date名称对应

丢失的PHP变量,最后一次出现在Chrome中,与$quote\u date名称对应,php,Php,我似乎找不到我的PHP变量$quote\u date。我有一个表单,可以从数据库中获取作业记录,并在表单中显示作业的当前进度,以便编辑、提交和更新到数据库。正在正确收集和显示作业的所有其他记录,但$quote_日期在操作中丢失。然而,当我在renderForm()函数执行后回显$quote_date时,它似乎确实存在,至少在那个时候是这样。为什么表单中没有显示$quote_日期 > 开始日期: > 菲斯克印刷: 在renderForm函数的参数列表中,变量名为$quoted\u date(如

我似乎找不到我的PHP变量$quote\u date。我有一个表单,可以从数据库中获取作业记录,并在表单中显示作业的当前进度,以便编辑、提交和更新到数据库。正在正确收集和显示作业的所有其他记录,但$quote_日期在操作中丢失。然而,当我在renderForm()函数执行后回显$quote_date时,它似乎确实存在,至少在那个时候是这样。为什么表单中没有显示$quote_日期


>
开始日期:
>
菲斯克印刷:

renderForm
函数的参数列表中,变量名为
$quoted\u date
(如“quote”,引号的过去时)。我想把它改成
$quote\u date='
很好地找到了@Phil,谢谢!问题解决了。
<?php

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// Allow the user to both create new records and edit existing records.
// Connect to the database.
$connect = mysqli_connect('localhost', 'username', 'password', 'database');
if ( !$connect ) {
  die( 'connect error: '.mysqli_connect_error() );
}

// creates the new/edit record form.
// since this form is used multiple times in this file, I have made it a function that is easily reusable

function renderForm($error = '', $id = '', $start_date = '', $company = '', $stock_code = '', $card_quantity = '', $fiske_print = '', $carrier_quantity = '', $quoted = '', $quote_details = '', $quoted_date = '', $quote_accepted = '', $quote_accepted_date = '', $proof_sent = '', $proof_sent_date = '', $proof_approved = '', $proof_approved_date = '', $printed = '', $print_date = '', $closed_loop_allocated = '', $invoiced = '', $invoiced_date = '', $posted = '', $tracking_number = '', $postal_date = '', $paid = '', $is_bulk_load = '', $bulk_funds_recieved = '', $cards_loaded = '', $notes = '', $completed = '')
{

?>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>

<body>
<?php
    $pageName = 'overview';
?>

<?php
    include('header.php');
?>

<h1><?php
    if ($id != '') {
        echo "Edit Record";
    } else {
        echo "New Record";
    }
?></h1>
<?php
    if ($error != '') {
        echo "<div style='padding:4px; border:1px solid red; color:red'>" . $error . "</div>";
    }
?>

<form action="" method="post">
<div>

    <table>
        <tr>
            <td colspan="2" style="text-align:center;"><strong>Job Details</strong></td>
            <td colspan="2" style="text-align:center;"><strong>Job Progress</strong></td>
        </tr>
        <tr>
            <td>ID: </td>
            <td><input type="text" name="id" value="<?php echo $id; ?>" readonly></td>
            <td>Quoted: </td>
            <td><input type="checkbox" name="quoted" value="1" <?php if($quoted == 1){echo 'checked';} ?>></td>
        </tr>
        <tr>
            <td>Start Date: </td>
            <td><input type="date" name="start_date" value="<?php if($start_date !== ''){echo date('Y-m-d',strtotime($start_date));} ?>"></td>
            <td>Quote Details: </td>
            <td><input type="text" name="quote_details" size="40" value="<?php echo $quote_details; ?>"></td>
        </tr>
        <tr>
            <td>Company: </td>
            <td><input type="text" name="company" size="40" value="<?php echo $company; ?>"></td>
            <td>Quote Date: </td>


// Here is where the mystery lies why is my $quote_date variable missing?
            <td><input type="date" name="quote_date" value="<?php echo date('Y-m-d',strtotime($quote_date)); ?>"></td><?php echo '<script type="text/javascript">alert("'.$quote_date.'");</script>'; ?>
        </tr>
        <tr>
            <td>Stock Code: </td>
            <td>
                <div id="billdesc">
                    <select id="test" name="stock_code">
                        <option class="non" value="GS01">GS01</option>
                        <option class="non" value="GS03">GS03</option>
                        <option class="non" value="SM01">SM01</option>
                        <option class="non" value="SM11">SM11</option>
                        <option class="non" value="CG01">CG01</option>
                        <option class="non" value="CG38">CG38</option>
                        <option class="editable" value="Other">Other</option>
                    </select>
                    <input class="editOption" style="display:none;" placeholder="Text juaj"></input>
                </div>
            </td>
            <td>Quote Accepted: </td>
            <td><input type="checkbox" name="quote_accepted" value="1" <?php if($quote_accepted == 1){echo 'checked';} ?>></td>
        </tr>
        <tr>
            <td>Card Quantity: </td>
            <td><input type="text" name="card_quantity" value="<?php echo $card_quantity; ?>"></td>
            <td>Quote Accepted Date: </td>
            <td><input type="date" name="quote_accepted_date" value="<?php if($quote_accepted_date !== ''){echo date('Y-m-d',strtotime($quote_accepted_date));} ?>"></td>
        </tr>
        <tr>
            <td>Carrier Quantity: </td>
            <td><input type="text" name="carrier_quantity" value="<?php echo $carrier_quantity; ?>"></td>
            <td>Proof Sent: </td>
            <td><input type="checkbox" name="proof_sent" value="1" <?php if($proof_sent == 1){echo 'checked';} ?>></td>
        </tr>
        <tr>
            <td>Fiske Print: </td>
            <td><input type="checkbox" name="fiske_print" value="1" <?php if($fiske_print == 1){echo 'checked';} ?>></td>
            <td>Proof Sent Date: </td>
            <td><input type="date" name="proof_sent_date" value="<?php if($proof_sent_date !== ''){echo date('Y-m-d',strtotime($proof_sent_date));} ?>"></td>
        </tr>
        <tr>
            <td rowspan="6" colspan="2" style="text-align:center;">
                Notes:<br>
                <textarea name="notes" rows="8" cols="70"><?php echo $notes; ?></textarea>
            </td>
            <td style="text-align:right;">Proof Approved: </td>
            <td style="text-align:left;"><input type="checkbox" name="proof_approved" value="1" <?php if($proof_approved == 1){echo 'checked';} ?>></td>
        </tr>
        <tr>
            <td>Proof Approved Date: </td>
            <td><input type="date" name="proof_approved_date" value="<?php if($proof_approved_date !== ''){echo date('Y-m-d',strtotime($proof_approved_date));} ?>"></td>
        </tr>
        <tr>
            <td>Printed: </td>
            <td><input type="checkbox" name="printed" value="1" <?php if($printed == 1){echo 'checked';} ?>></td>
        </tr>
        <tr>
            <td>Print Date</td>
            <td><input type="date" name="printed_date" value="<?php if($print_date !== ''){echo date('Y-m-d',strtotime($print_date));} ?>"></td>
        </tr>
        <tr>
            <td>Closed Loop Allocated: </td>
            <td><input type="checkbox" name="closed_loop_allocated" value="1" <?php if($closed_loop_allocated == 1){echo 'checked';} ?>></td>
        </tr>
        <tr>
            <td>Invoiced: </td>
            <td><input type="checkbox" name="invoiced" value="1" <?php if($invoiced == 1){echo 'checked';} ?>></td>
        </tr>
        <tr>
            <td>Paid: </td>
            <td><input type="checkbox" name="paid" value="1" <?php if($paid == 1){echo 'checked';} ?>></td>
            <td>Invoice Date: </td>
            <td><input type="date" name="invoice_date" value="<?php if($invoice_date !== ''){echo date('Y-m-d',strtotime($invoice_date));} ?>"></td>
        </tr>
        <tr>
            <td>Is Bulk Load: </td>
            <td><input type="checkbox" name="is_bulk_load" value="1" <?php if($is_bulk_load == 1){echo 'checked';} ?>></td>
            <td>Posted: </td>
            <td><input type="checkbox" name="posted" value="1" <?php if($posted == 1){echo 'checked';} ?>></td>
        </tr>
        <tr>
            <td>Bulk Funds Recieved</td>
            <td><input type="checkbox" name="bulk_funds_recieved" value="1" <?php if($bulk_funds_received == 1){echo 'checked';} ?> ></td>
            <td>Postal Date: </td>
            <td><input type="date" name="postal_date" value="<?php if($postal_date !== ''){echo date('Y-m-d',strtotime($postal_date));} ?>"></td>
        </tr>
        <tr>
            <td>Cards Loaded: </td>
            <td><input type="checkbox" name="cards_loaded" value="1" <?php if($cards_loaded == 1){echo 'checked';} ?>></td>
            <td>Tracking Number: </td>
            <td><input type="text" name="tracking_number" size="30" value="<?php echo $tracking_number; ?>"></td>
        </tr>
        <tr>
            <td colspan="4" style="text-align:center;">
                Completed: <input type="checkbox" name="completed" value="1" <?php if($completed == 1){echo 'checked';} ?>>&nbsp;&nbsp;
                <input type="submit" name="submit" value="Save" style="width:90px" />
            </td>
        </tr>
    </table>

<script type="text/javascript">
var initialText = $('.editable').val();
$('.editOption').val(initialText);

$('#test').change(function(){
var selected = $('option:selected', this).attr('class');
var optionText = $('.editable').text();

if(selected == "editable"){
  $('.editOption').show();


  $('.editOption').keyup(function(){
      var editText = $('.editOption').val();
      $('.editable').val(editText);
      $('.editable').html(editText);
  });

}else{
  $('.editOption').hide();
}
});
</script>

</body>
</html>

<?php
}

/*

EDIT RECORD

*/
// if the 'id' variable is set in the URL, we know that we need to edit an existing record
if (isset($_GET['id'])) {
    // if the form's submit button is clicked, we need to process the form
    if (isset($_POST['submit'])) {
        // make sure the 'id' in the URL is valid
        if (is_numeric($_POST['id'])) {
            // get the form data
            // I'll get to this later... get form to display first...
            echo 'We are saving a new edit of job ' . $id;
        }
        // if the 'id' variable is not valid, show an error message
        else {
            echo "Error!";
        }
    }
    // if the form hasn't been submitted yet, get the info from the database and show the form
    else {
        // make sure the 'id' value is valid
        if (is_numeric($_GET['id']) && $_GET['id'] > 0) {
            // get 'id' from URL
            $id = $_GET['id'];

            // get the record from database
            if ($stmt = $connect->prepare("SELECT id, start_date, company, stock_code, card_quantity, fiske_print, carrier_quantity, quoted, quote_details, quoted_date, quote_accepted, quote_accepted_date, proof_sent, proof_sent_date,proof_approved, proof_approved_date, printed, print_date, closed_loop_allocated, invoiced, invoiced_date, posted, tracking_number, postal_date, paid, is_bulk_load, bulk_funds_received, cards_loaded, notes, completed FROM jobs WHERE id = ?")) {
                $stmt->bind_param("s", $id);
                $stmt->execute();

                $stmt->bind_result($id,$start_date,$company,$stock_code,$card_quantity,$fiske_print,$carrier_quantity,$quoted,$quote_details,$quote_date,$quote_accepted,$quote_accepted_date,$proof_sent,$proof_sent_date,$proof_approved,$proof_approved_date,$printed,$printed_date,$closed_loop_allocated,$invoiced,$invoice_date,$posted,$tracking_number,$postal_date,$paid,$is_bulk_load,$bulk_funds_received,$cards_loaded,$notes,$completed);

                /* fetch values */
                while ($stmt->fetch()) {
                    printf("%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s\n", $id,$start_date,$company,$stock_code,$card_quantity,$fiske_print,$carrier_quantity,$quoted,$quote_details,$quote_date,$quote_accepted,$quote_accepted_date,$proof_sent,$proof_sent_date,$proof_approved,$proof_approved_date,$printed,$printed_date,$closed_loop_allocated,$invoiced,$invoice_date,$posted,$tracking_number,$postal_date,$paid,$is_bulk_load,$bulk_funds_received,$cards_loaded,$notes,$completed);
                }

                // show the form by executing renderForm()
                renderForm(NULL, $id,$start_date,$company,$stock_code,$card_quantity,$fiske_print,$carrier_quantity,$quoted,$quote_details,$quote_date,$quote_accepted,$quote_accepted_date,$proof_sent,$proof_sent_date,$proof_approved,$proof_approved_date,$printed,$printed_date,$closed_loop_allocated,$invoiced,$invoice_date,$posted,$tracking_number,$postal_date,$paid,$is_bulk_load,$bulk_funds_received,$cards_loaded,$notes,$completed);
                // check to see if we have a quote date..?
                echo 'quote date: '.$quote_date;

                $stmt->close();
            }
            // show an error if the query has an error
            else {
                echo "Error: could not prepare SQL statement";
            }
        }
        // if the 'id' value is not valid, redirect the user back to the view.php page
        else {
            header("Location: addJob.php");
        }
    }
}

/*

NEW RECORD

*/
// if the 'id' variable is not set in the URL, we must be creating a new record
else {
    // if the form's submit button is clicked, we need to process the form
    if (isset($_POST['submit'])) {
        // get the form data
        $start_date = date("Y-m-d", strtotime($_POST['start_date']));
        $company = $_POST['company'];
        $stock_code = $_POST['stock_code'];
        $card_quantity = $_POST['card_quantity'];
        $carrier_quantity = $_POST['carrier_quantity'];
        $fiske_print = $_POST['fiske_print'];
        $quoted = $_POST['quoted'];
        $quote_details = $_POST['quote_details'];
        $quote_date = date("Y-m-d", strtotime($_POST['quote_date']));
        $quote_accepted = $_POST['quote_accepted'];
        $quote_accepted_date = date("Y-m-d", strtotime($_POST['quote_accepted_date']));
        $proof_sent = $_POST['proof_sent'];
        $proof_sent_date = date("Y-m-d", strtotime($_POST['proof_sent_date']));
        $proof_approved = $_POST['proof_approved'];
        $proof_approved_date = date("Y-m-d", strtotime($_POST['proof_approved_date']));
        $printed = $_POST['printed'];
        $printed_date = date("Y-m-d", strtotime($_POST['printed_date']));
        $closed_loop_allocated = $_POST['closed_loop_allocated'];
        $invoiced = $_POST['invoiced'];
        $invoice_date = date("Y-m-d", strtotime($_POST['invoice_date']));
        $posted = $_POST['posted'];
        $postal_date = date("Y-m-d", strtotime($_POST['postal_date']));
        $tracking_number = $_POST['tracking_number'];
        $paid = $_POST['paid'];
        $is_bulk_load = $_POST['is_bulk_load'];
        $bulk_funds_received = $_POST['bulk_funds_received'];
        $cards_loaded = $_POST['cards_loaded'];
        $completed = $_POST['completed'];

        /* Prepare an insert statement */
        $query = "INSERT INTO jobs (start_date,company,stock_code,card_quantity,fiske_print,carrier_quantity,quoted,quote_details,quoted_date,quote_accepted,quote_accepted_date,proof_sent,proof_sent_date,proof_approved,proof_approved_date,printed,print_date,closed_loop_allocated,invoiced,invoiced_date,posted,tracking_number,postal_date,paid,is_bulk_load,bulk_funds_received,cards_loaded,notes,completed) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
        $stmt = mysqli_prepare($connect, $query);

        mysqli_stmt_bind_param($stmt, "sssssssssssssssssssssssssssss", $start_date,$company,$stock_code,$card_quantity,$fiske_print,$carrier_quantity,$quoted,$quote_details,$quote_date,$quote_accepted,$quote_accepted_date,$proof_sent,$proof_sent_date,$proof_approved,$proof_approved_date,$printed,$printed_date,$closed_loop_allocated,$invoiced,$invoice_date,$posted,$tracking_number,$postal_date,$paid,$is_bulk_load,$bulk_funds_received,$cards_loaded,$notes,$completed);

        /* Execute the statement */
        mysqli_stmt_execute($stmt);

        /* close statement */
        mysqli_stmt_close($stmt);

        // redirect the user
        header("Location: index.php");

    }
    // if the form hasn't been submitted yet, show the form
    else {
        error_log('SQL error ('.__FILE__.' line '.__LINE__.'): '. $connect->error);
        renderForm();
    }
}

// close the mysqli connection
$connect->close();

?>