dongqiao3927 2016-10-19 16:15
浏览 35

这个PHP代码有什么问题,它不会插入数据?

I ran this on Xamp 5.538. The name of the file is application.php. The form appears normally and I get no error messages. However, it does not insert data into the MYSQL database. So far I have only been trying to get the top portion of the form to work; once it does I fill in the rest in the code. My database is named employees; the table’s name is table1. It contains the following fields so far: First, last, mi, address, city, state, zip, phone, email, ss, dob, security I tryed to post the entire form but wasn't smart enough to figure out how to do it or maybe it's just that I hate puzzles. Please figure this out for me. I’ve come along way, but still have further to go. Thank You; Eric Here’s the code:

<?php
// Your database info
    $db_host = 'localhost';
    $db_user = 'root';
    $db_pass = '""';
    $db_name = 'employees';
if (!empty($_POST))
{
    $con = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
    if ($con‐>connect_error)
die('Connect Error (' . mysqli_connect_errno() . ') '.
mysqli_connect_error());
    $sql = "INSERT INTO table1 (first, last, mi, address, city, state, zip, phone, email, ss, dob, security) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)";
    if (!$stmt = $con‐>prepare($sql))
die('Query failed: (' . $con‐errno . ') ' . $con‐error);
    if (!$stmt‐    >bind_param('ssi',$_POST['fist'],$_POST['last'],$_POST['mi'],$_POST['address'],$ _POST['city'],$_POST['state'],$_POST['zip'],$_POST['phone'],$_POST['email'],$_PO    ST['ss'],$_POST['dob'],$_POST['security']))
die('Bind Param failed: (' . $con‐errno . ') ' . $con‐error);
    if (!$stmt‐>execute())
die('Insert Error ' . $con‐>error);
echo "Record added";
$stmt‐>close();
$con‐>close();

}
?>
  • 写回答

1条回答 默认 最新

  • doujianzi8521 2016-10-19 17:28
    关注
    if (!empty($_POST['sub'])) {
    $father = $_POST['father'];
    $con = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
    if (!$con) {
        die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
    }
    echo $sql = "INSERT INTO `father`( `FirstName`) VALUES ('" . $father . "')";
    if (!$stmt = mysqli_prepare($con, $sql)) {
        echo "done";
    }
    if ($stmt->execute()) {
        // it worked
    } else {
        // it didn't
    }}
    

    use this code it is working

    评论

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用