发布表单数据,但只有一个具有未定义的索引错误

时间:2018-04-02 03:11:20

标签: php forms post indexing undefined

我一直在寻找答案,没有运气。有一个可能的相关帖子,但没有答案可用。

我通过帖子操作将表单数据发布到自己。然后我将所有发布的值重新发送到将它们发送到mysql表之前。

<?php 
require_once 'config.php'; 
    $gemBarcode = $gemSpec = $gemVar = $gemWeigh = $gemShape = $gemCut = $gemCol = $gemBrill = $gemClear = $gemTreat = $gemCertNum = $gemLWarehouse=""; 
    $gemDesc=""; 
    $createdDate = $modifiedDate = $gemChecked =""; 
    $gemW = $gemH = $gemCert =0; 
    $gemlength = 0; 
//if form is submitted
if($_SERVER["REQUEST_METHOD"] == "POST") {
//form actions once submitted (Ie: Check the validity, and if all ok submit to server) - I will complete this later 

    $gemBarcode = $_POST['gemBarcode'];
    $gemSpec = $_POST['gemSpec'];
    $gemVar = $_POST['gemVar'];
    $gemWeigh = $_POST['gemWeigh'];
    $gemShape = $_POST['gemShape'];
    $gemCut = $_POST['gemCut'];
    $gemCol = $_POST['gemCol'];
    $gemBrill = $_POST['gemBrill'];
    $gemClear = $_POST['gemClear'];
    $gemTreat = $_POST['gemTreat'];
    $gemCertNum = $_POST['gemCertNum'];
    $gemLWarehouse=  $_POST['gemLWarehouse'];
    $gemDesc =  $_POST['gemDesc'];
    $createdDate = date("Y-m-d"); 
    $modifiedDate = date("Y-m-d"); 
    $gemChecked = date("Y-m-d"); 
    $gemW = $_POST['gemW'];
    $gemH = $_POST['gemH'];
    $gemlength = $_POST['gemlength']; 
    $gemCert = $_POST['gemCert'];

// $sqlstatement=$mysqli->prepare();

$sql = "INSERT INTO stockitems (gemBarcode, gemSpec, gemVar, gemWeigh, gemShape, gemCut, gemClear, gemW, gemH, gemL, gemCol, gemBrill, gemTreat, gemCert, gemCertNum, gemLWarehouse, createdDate, modifiedDate, gemChecked, gemDesc) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"; 

    if($stmt=$mysqli->prepare($sql)){
        $stmt->bind_param("sssssssdddsssissssss",$Para_gemBarcode, $Para_gemSpec, $Para_gemVar, $Para_gemWeigh, $Para_gemShape, $Para_gemCut, $Para_gemClear, $Para_gemW, $Para_gemH, $Para_gemLen, $Para_gemCol, $Para_gemBrill, $Para_gemTreat, $Para_gemCert, $Para_gemCertNum, $Para_gemLWarehouse, $Para_createdDate, $Para_modifiedDate, $Para_gemChecked, $Para_gemDesc);
        $Para_gemBarcode = $gemBarcode; 
        $Para_gemSpec = $gemSpec;
        $Para_gemVar = $gemVar; 
        $Para_gemWeigh = $gemWeigh;
        $Para_gemShape = $gemShape; 
        $Para_gemCut = $gemCut;
        $Para_gemCol = $gemCol; 
        $Para_gemBrill = $gemBrill;
        $Para_gemClear = $gemClear;
        $Para_gemTreat = $gemTreat; 
        $Para_gemCertNum = $gemCertNum; 
        $Para_gemLWarehouse =$gemLWarehouse;
        $Para_gemDesc = $gemDesc;
        $Para_createdDate = $createdDate; 
        $Para_modifiedDate = $modifiedDate; 
        $Para_gemChecked = $gemChecked; 
        $Para_gemW = $gemW; 
        $Para_gemH = $gemH; 
        $Para_gemLen = $gemlength; 
        $Para_gemCert  = $gemCert; 

        if ($stmt->execute()){
            echo "Successfully executed <br>"; 
            //WILL REDIRECT
        } else {
            echo "Execution Failed: <br> ".$mysqli->errno.": ".$mysqli->error; 
        }

    }
    //$stmt->close(); - any idea why this is throwing an error? 
    $mysqli->close(); 

}
?>
<!DOCTYPE HTML> 
<html lang="eng"> 
<head> 
<meta charset="UTF-8">
<title>Add New Gemstone</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">
<style type="text/css"> 
    * { font-family: "arial"; }
    .wrapper {
        width: 90%; 
        margin: 0 auto; 
    }
</style>
</head>
<body> 

    <div class="wrapper"> 
        <form class='form-inline' action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">

            <div class='row'> 
                <label class='col-md-2' for='gemBarcode'>Barcode</label>
                <input type='number' class='form-control col-md-2' name='gemBarcode' placeholder='Barcode' required  value='<?php echo $gemBarcode;?>'> 
            </div>  

            <div class='row'>
                <label class='col-md-2' for='gemSpec'>Species</label>
                <input type='text' class='form-control col-md-2' name='gemSpec' placeholder='Species'   value='<?php echo $gemSpec;?>'> 
                <label class='col-md-2' for='gemVar'>Variant</label>
                <input type='text' class='form-control com-md-3' name='gemVar' placeholder='Variant'   value='<?php echo $gemVar;?>'>
            </div>  

            <div class='row'>
                <label class='col-md-2' for='gemWeigh'>Weight</label>
                <input type='text' class='form-control col-md-2' name='gemWeigh' placeholder='Gem Weight (ct/g)'   value='<?php echo $gemWeigh;?>'>

                <label class='col-md-2' for='gemShape'>Shape</label>
                <input type='text' class='form-control col-md-2' name='gemShape' placeholder='Shape'   value='<?php echo $gemShape;?>'> 

                <label class='col-md-2' for='gemCut'>Cut</label>
                <input type='text' class='form-control col-md-2' name='gemCut' placeholder='Cut'   value='<?php echo $gemCut;?>'> 
            </div>  
            <div class='row'>
                <label class='col-md-2' for='gemW'>Width</label>
                <input type='number' class='form-control col-md-2' name='gemW' placeholder='Width (mm)' step='Any'  value='<?php echo $gemW;?>'> 

                <label class='col-md-2' for='gemH'>Height</label>
                <input type='number' class='form-control col-md-2' name='gemH' placeholder='Height (mm)' step='any'  value='<?php echo $gemH;?>'>

                <label class='col-md-2' for='gemlength'>Length</label> 
                <input type='number' class='form-control col-md-2' name='gemlength' placeholder='Length (mm)' step='any' value='<?php echo $gemlength; ?>'> 
            </div>  
            <div class='row'>
                <label class='col-md-2' for='gemCol'>Colour</label>
                <input type='text' class='form-control col-md-2' name='gemCol' placeholder='Colour'   value='<?php echo $gemCol;?>'> 

                <label class='col-md-2' for='gemBrill'>Brilliance</label>
                <input type='text' class='form-control col-md-2' name='gemBrill' placeholder='Brilliance'   value='<?php echo $gemBrill;?>'>

                <label class='col-md-2' for='gemClear'>Clarity</label>
                <input type='text' class='form-control col-md-2' name='gemClear' placeholder='Clarity'   value='<?php echo $gemClear;?>'> 
            </div>  
            <div class='row'>
                <label class='col-md-2' for='gemTreat'>Enhancement</label>
                <input type='text' class='form-control col-md-2' name='gemTreat' placeholder='Enhanced'   value='<?php echo $gemTreat;?>'>

                <div class='col'>
                    <label class='col-md-2' for='gemCert'>Certified</label>
                    <select class='form-control col-md-2' style='width=auto !important;' name='gemCert'> 
                        <option></option>
                        <option value=1>Yes</option>
                        <option value=2>No</option>
                    </select>
                </div>

                <label class='col-md-2' for='gemCertNum'>Certificate Number</label>
                <input type='text' class='form-control col-md-2' name='gemCertNum' placeholder='Certificate Number'   value='<?php echo $gemCertNum;?>'> 
            </div>  

            <div class='row'>
                <label class='col-md-2' for='gemLWarehouse'>Warehouse</label>
                <input type='text' class='form-control col-md-2' name='gemLWarehouse' placeholder='Gem Location'   value='<?php echo $gemLWarehouse;?>'>

                <label class='col-md-2' for='gemDesc'>Description</label>
                <input type='text' class='form-control col-md-7' name='gemDesc' placeholder=''   value='<?php echo $gemDesc;?>'> 
            </div>  

            <div class='row'>
                <label class='col-md-2' for='createdDate'>Created</label>
                <input type='date' class='form-control col-md-2' name='createdDate' placeholder='Date Loaded'   value='<?php echo $createdDate;?>'>

                <label class='col-md-2' for='modifiedDate'>Modified</label>
                <input type='date' class='form-control col-md-2' name='modifiedDate' placeholder='Date last Changed'   value='<?php echo $modifiedDate;?>'>

                <label class='col-md-2' for='gemChecked'>Checked</label>
                <input type='date' class='form-control col-md-2' name='gemChecked' placeholder='Date last Checked'   value='<?php echo $gemChecked;?>'> 
            </div>
            <div class='row'> 
                <input type='submit' class='btn btn-primary' value='submit'>
                <a href='index.php' class='btn btn-defaul'>Cancel</a>
        </div>
        </form>
    </div>

    </body>

    </html>

注意: - 请原谅拼写 - 阅读障碍。我在单词长度方面遇到了很多麻烦,(有时拼写它很长)但我重做这些并且它们都是一致的。另请注意:颜色拼写在南非,美国的颜色。

编辑:错误在此行中被选中:     $ gemlength = $ _POST [&#39; gemlength&#39;]; 我的拼写不是问题,我已经检查并重新检查了。

1 个答案:

答案 0 :(得分:0)

我不知道为什么,但突然间它再次开始工作,我没有改变任何事情。哦,不管怎样,谢谢!