尝试使用php

时间:2018-06-02 21:08:39

标签: php html mysql mysqli

感谢您阅读本文。我正在尝试创建一个使用php将信息提交到MySQL数据库的html表单。

我对此非常陌生,所以一直在网上借用代码并使其合适。还有一些我想在以后扩展的东西,但现在我很想让这个简单的形式工作......

这是我在尝试提交表单时收到的错误:

( ! ) Notice: Undefined index: Split_Exposure in C:\wamp64\www\insert.php on line 23

( ! ) Notice: Undefined index: Trial_Exposure in C:\wamp64\www\insert.php on line 27

( ! ) Notice: Undefined index: Reshoot_Exposure in C:\wamp64\www\insert.php on line 28

( ! ) Notice: Undefined index: Check_Shot in C:\wamp64\www\insert.php on line 29

( ! ) Notice: Undefined variable: Source_ID in C:\wamp64\www\insert.php on line 33

 ERROR: Could not able to execute INSERT INTO production (OperatorID, SerialNo, Aspect, Bay, FilmCount, Source, SourceStrength, Xray_kV, Xray_mA, ExposureRads, SplitExposure, ExposureHours, ExposureMinutes, ExposureSeconds, TrialExposure, Reshoot, CheckShot) VALUES ('1001', 'help', 'me', '1', '3', '', '', '', '', '', '', '', '', '', '', '', ''). Incorrect integer value: '' for column 'Xray_kV' at row 1'

这是我的表格:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Add Records Form</title>
</head>
<body>
<center><img src="images\logo.jpg"></center>
<form action="insert.php" method="post">
<table border="0"  frame="border" align="center">
<tr>
    <td>
        <label for="OperatorID">Operator ID:</label>
    </td>
    <td>
        <input type="number" required="yes" maxlength="4" Size="4" name="Operator_ID" id="OperatorID">
    </td>
    </tr>
    <tr>
    <td>
            <label for="SerialNo">Serial Number:</label>
    </td>
    <td>
        <input type="text" required="yes" name="Serial_No" id="SerialNo">
 </td>
    </tr>
    <tr>
    <td>    
        <label for="Aspect">Aspect:</label>
            </td>
    <td>
        <input type="text" required="yes" name="Aspect_Id" id="Aspectid">
   </td>
    </tr>
    <tr>
    <td>
        <label for="Bay">Bay Number:</label>
            </td>
    <td>
        <input type="number" maxlength="1" required="yes" size="1" name="Bay_No" id="BayNo">
 </td>
    </tr>
    <tr>
    <td>
        <label for="FilmCount">Number of films:</label>
            </td>
    <td>
        <input type="number" maxlength="2" required="yes" size="2" name="Film_Count" id="FilmCount">
</td>
    </tr>
    <tr>
    <td>
        <label for="Source">Source Used:</label>
            </td>
    <td>
        <input type="text" required="yes" name="Source_Id" id="SourceId">
</td>
    </tr>
    <tr>
    <td>
        <label for="SourceStrength">Source Strength (Gamma Only):</label>
            </td>
    <td>
        <input type="text" name="Source_Strength" id="SoureStrength">
</td>
    </tr>
    <tr>
    <td>
        <label for="Xray_kV">X-Ray Voltage:</label>
            </td>
    <td>
        <input type="text" name="Xray_kV" id="XraykV">
</td>
    </tr>
    <tr>
    <td>
        <label for="Xray_mA">X-ray mA:</label>
            </td>
    <td>
        <input type="text" name="Xray_mA" id="XraymA">
</td>
    </tr>
    <tr>
    <td>
        <label for="ExposureRads">Exposure in RADS:<br><font size="2">*For split exposures check the next box and<br>enter the split exposure not the total exposure.</font></label>
            </td>
    <td align="top">
        <input type="number" maxlength="4" name="Exposure_Rads" id="ExposureRads">
</td>
    </tr>
    <tr>
    <td>
        <label for="SplitExposure">Split Exposure?</label>
            </td>
    <td>
        <input type="checkbox" name="Split_Exposure" id="SplitExposure">  
</td>
    </tr>
    <tr>
    <td>
        <label for="ExposureHours">X&Y only: Exposure length HH:</label>
            </td>
    <td>
        <input type="number" maxlength="2" name="Exposure_Hours" id="ExposureHours">
 </td>
    </tr>
    <tr>
    <td>
        <label for="ExposureMins">X&Y only: Exposure length MM:</label>
            </td>
    <td>
        <input type="number" maxlength="2" name="Exposure_Mins" id="ExposureMins">
</td>
    </tr>
    <tr>
    <td>
        <label for="ExposureSecs">X&Y  only: Exposure length SS:</label>
            </td>
    <td>
        <input type="number" maxlength="2" name="Exposure_Secs" id="ExposureSecs">
  </td>
    </tr>
    <tr>
    <td>
        <label for="TrailExposure">Trial Exposure?</label>
            </td>
    <td>
        <input type="checkbox" name="Trial_Exposure" id="TrialExposure">
</td>
    </tr>
    <tr>
    <td>
        <label for="ReshootExposure">Reshoot  Exposure?</label>
                </td>
    <td>
        <input type="checkbox" name="Reshoot_Exposure" id="ReshootExposure">
</td>
    </tr>
    <tr>
    <td>
        <label for="CheckShot">Check Shot?</label>
            </td>
    <td>
        <input type="checkbox" name="Check_Shot" id="CheckShot">
</td>
    </tr>
    <tr>
    <td>
        <input type="submit" value="Add Record">
    </td>
        </tr>
    </table>

    </form>
</body>
</html>

这是我的insert.php

<?php
include 'config.php';
/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
$link = mysqli_connect("$host", "$username", "$password", "$database");

// Check connection
if($link === false){
    die("ERROR: Could not connect. " . mysqli_connect_error());
}

// Escape user inputs for security
$Operator_ID = mysqli_real_escape_string($link, $_REQUEST['Operator_ID']);
$Serial_No = mysqli_real_escape_string($link, $_REQUEST['Serial_No']);
$Aspect_Id = mysqli_real_escape_string($link, $_REQUEST['Aspect_Id']);
$Bay_No = mysqli_real_escape_string($link, $_REQUEST['Bay_No']);
$Film_Count = mysqli_real_escape_string($link, $_REQUEST['Film_Count']);
$Source_Id = mysqli_real_escape_string($link, $_REQUEST['Source_Id']);
$Source_Strength = mysqli_real_escape_string($link, $_REQUEST['Source_Strength']);
$Xray_kV = mysqli_real_escape_string($link, $_REQUEST['Xray_kV']);
$Xray_mA = mysqli_real_escape_string($link, $_REQUEST['Xray_mA']);
$Exposure_Rads = mysqli_real_escape_string($link, $_REQUEST['Exposure_Rads']);
$Split_Exposure = mysqli_real_escape_string($link, $_REQUEST['Split_Exposure']);
$Exposure_Hours = mysqli_real_escape_string($link, $_REQUEST['Exposure_Hours']);
$Exposure_Mins = mysqli_real_escape_string($link, $_REQUEST['Exposure_Mins']);
$Exposure_Secs = mysqli_real_escape_string($link, $_REQUEST['Exposure_Secs']);
$Trial_Exposure = mysqli_real_escape_string($link, $_REQUEST['Trial_Exposure']);
$Reshoot_Exposure = mysqli_real_escape_string($link, $_REQUEST['Reshoot_Exposure']);
$Check_Shot = mysqli_real_escape_string($link, $_REQUEST['Check_Shot']);


// attempt insert query execution
$sql = "INSERT INTO production (OperatorID, SerialNo, Aspect, Bay, FilmCount, Source, SourceStrength, Xray_kV, Xray_mA, ExposureRads, SplitExposure, ExposureHours, ExposureMinutes, ExposureSeconds, TrialExposure, Reshoot, CheckShot) VALUES ('$Operator_ID', '$Serial_No', '$Aspect_Id', '$Bay_No', '$Film_Count', '$Source_ID', '$Source_Strength', '$Xray_kV', '$Xray_mA', '$Exposure_Rads', '$Split_Exposure', '$Exposure_Hours',  '$Exposure_Mins', '$Exposure_Secs',  '$Trial_Exposure', '$Reshoot_Exposure', '$Check_Shot')";
if(mysqli_query($link, $sql)){
    echo "Record added successfully.";
} else{
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}

// close connection
mysqli_close($link);
?>

道歉,我不确定如何从phpmyadmin粘贴我的表结构 - 如果你可以就此提出建议我会很高兴发布它:)

提前致谢

JM

0 个答案:

没有答案