gpt4 book ai didi

php - 我无法将我的 html 表单链接到 mysql 表?

转载 作者:行者123 更新时间:2023-11-29 11:33:33 25 4
gpt4 key购买 nike

我创建了一个名为“employee.php”的表单页面,用于接收用户数据。另外,我还有另一个名为 SQLConnectionProcess.php 的文件,其中包含用于将employee.php 中的表单链接到sql 表的代码。数据库的名称是“员工信息”,表的名称是“员工信息”。我正在使用 phpmyadmin 和 XAMPP 进行本地服务器测试。

employee.php代码:

<html>
<body>

<form name="EmployeeDatabase" action="SQLConnectionProcess.php" method="post">

<link rel="stylesheet" href="css.css">

<h1>EMPLOYEE DATABASE</h1>

Employe Card NO: <input type="text" name="cardNO" ><br><br>
Employee NO: <input type="text" name="employeeNO" ><br><br>
Employee Name: <input type="text" name="employeename"><br><br>
Nationality: <input type="text" name="nationality"><br><br>
Profession: <input type="text" name="profession"><br><br>
DOB: <input type="text" name="DOB"><br><br>
DOJ: <input type="text" name="DOJ"><br><br>
DOA(VisitVisa): <input type="text" name="DOA"><br><br>
Company Code: <input type="text" name="companycode"><br><br>
Sponsor Code: <input type="text" name="sponsorcode"><br><br>
Visa Type: <input type="text" name="visatype"><br><br>
Status: <input type="text" name="status"><br><br>

<input type="submit" name="formSubmit" value="Submit">

</form>

</body>
</html>

SQLConnectionProcess.php代码:

if(isset($_POST['formSubmit'])){
$cardNO= $_POST['cardNO'];
$employeeNO= $_POST['employeeNO'];
$employeename= $_POST['employeename'];
$nationality= $_POST['nationality'];
$profession= $_POST['profession'];
$DOB= $_POST['DOB'];
$DOJ= $_POST['DOJ'];
$DOA= $_POST['DOA'];
$companycode = $_POST['companycode'];
$sponsorcode= $_POST['sponsorcode'];
$visatype= $_POST['visatype'];
$status= $_POST['status'];
mysqli_connect('localhost','root','password','employee information');
$sql = sprintf("INSERT INTO table_employee info(Employee Card NO,Employee NO,Employee Name,Nationality,Profession,DOB,DOJ,DOA(VisitVisa),Company Code,Sponsor Code,Visa Type,Status) VALUES ('','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')",$cardNO,$employeeNO,$employeename,$nationality,$profession,$DOB,$DOJ,$DOA,$companycode,$sponsorcode,$visatype,$status);
mysqli_query($sql);

但是当我从employee.php 提交表单时,我被重定向到一个新页面,其中显示了SQLConnectionProcess.php 中的所有代码。我无法找出编码错误。请帮助我......

最佳答案

使用下面的代码。

SQLConnectionProcess.php

<?php
if(isset($_POST['formSubmit'])){
$cardNO= isset($_POST['cardNO']) ? $_POST['cardNO'] : 0;
$employeeNO= isset($_POST['employeeNO']) ? $_POST['employeeNO'] : 0;
$employeename= isset($_POST['employeename']) ? $_POST['employeename'] : "";
$nationality= isset($_POST['nationality']) ? $_POST['nationality'] : "";
$profession= isset($_POST['profession']) ? $_POST['profession'] : "";
$DOB= isset($_POST['DOB']) ? $_POST['DOB'] : "";
$DOJ= isset($_POST['DOJ']) ? $_POST['DOJ'] : "";
$DOA= isset($_POST['DOA']) ? $_POST['DOA'] : "";
$companycode = isset($_POST['companycode']) ? $_POST['companycode'] : 0;
$sponsorcode= isset($_POST['sponsorcode']) ? $_POST['sponsorcode'] : 0;
$visatype= isset($_POST['visatype']) ? $_POST['visatype'] : "";
$status= isset($_POST['status']) ? $_POST['status'] : "";
$con = mysqli_connect('localhost','root','','employee information');
$sql = sprintf("INSERT INTO table_employee info(Employee Card NO,Employee NO,Employee Name,Nationality,Profession,DOB,DOJ,DOA(VisitVisa),Company Code,Sponsor Code,Visa Type,Status) VALUES ('','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')",$cardNO,$employeeNO,$employeename,$nationality,$profession,$DOB,$DOJ,$DOA,$companycode,$sponsorcode,$visatype,$status);
mysqli_query($con,$sql);
}
?>

关于php - 我无法将我的 html 表单链接到 mysql 表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36996932/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com