gpt4 book ai didi

PHP-MySQL INSERT 操作不工作

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

我正在开发一个网络平台。我正在使用 PHP 和 MySQL。我想将数据插入数据库。我的代码如下。

<?php
session_start();
require_once('../../system/database.php');

if ($_SERVER['REQUEST_METHOD'] == 'POST') {

$ownerid = (int)$_SESSION['id'];

$record_time = date('H:i:s');
$record_date = date('Y-m-d');

// form_data
$name = strip_tags($_POST['name']);
$surname = strip_tags($_POST['surname']);
$phone1 = strip_tags($_POST['phone1']);
$birthday = strip_tags(trim($_POST['birthday']));
$gender = strip_tags(trim($_POST['gender']));
$company = strip_tags(trim($_POST['company']));
$address1 = strip_tags(trim($_POST['address1']));
$address2 = strip_tags(trim($_POST['address2']));
$phone2 = strip_tags(trim($_POST['phone2']));
$mail1 = strip_tags(trim($_POST['mail1']));
$mail2 = strip_tags(trim($_POST['mail2']));
$about = strip_tags(trim($_POST['about']));
$type_of = strip_tags(trim($_POST['type_of']));
$visible = strip_tags(trim($_POST['visible']));

$query = "INSERT INTO contact (ownerid, name, surname, birthday, gender, address1, address2, phone1, phone2, mail1, mail2, about, type_of, visible, time, date) VALUES('$ownerid', '$name', '$surname', '$birthday', '$gender', '$address1', '$address2', '$phone1', '$phone2', '$mail1', '$mail2', '$mail1', '$mail2', '$about', '$type_of', '$visible', '$record_time', '$record_date')";
$result = mysqli_query($connection, $query);
mysqli_error($connection);

} else {
header('Location: ../new_contact.php');
}

但是我的 MySQL 代码不工作并写入任何错误消息!

最佳答案

values 子句中的列数错误(你重复两次 mail1 和 mail2)试试

$query = "INSERT INTO contact 
(ownerid, name, surname, birthday, gender, address1, address2, phone1,
phone2, mail1, mail2, about, type_of, visible, time, date)
VALUES('$ownerid', '$name', '$surname', '$birthday', '$gender', '$address1', '$address2', '$phone1',
'$phone2', '$mail1', '$mail2', '$about', '$type_of', '$visible', '$record_time', '$record_date')";

关于PHP-MySQL INSERT 操作不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42922074/

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