gpt4 book ai didi

php - 'Bob' 中的未知列 'field list' ... php 或 mysql 问题

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

我有一个奇怪的问题,我希望它是我忽略的愚蠢问题。

我收到一个错误,通常在 mysql 表中缺少列或拼写错误的 php 变量时发生:“‘field list’ 中的未知列‘Bob’”...

除了“Bob”不是列的名称,它是我试图分配给该行的 VALUE。为什么 php 会混淆这两者??

这是我认为是错误位置的 php 函数:

function recordGuest($id,$fname,$lname,$dinner){
$conn = connect("wedding");
$guest_query = "INSERT INTO guest (fname,lname,person_id)
VALUES (".$fname.",".$lname.",".$id.");";
mysql_query($guest_query,$conn) or die(mysql_error());

$guest_id_query = "SELECT id FROM guest WHERE person_id = ".$id.";";
$guest_id_result = mysql_query($guest_id_query,$conn) or die(mysql_error());
$guest_id = "";
while($row = mysql_fetch_array($guest_id_result)){
$guest_id = $row["id"];
}

$guest_dinner_query = " INSERT INTO guest_dinner (dinner_id,guest_id)
VALUES (".$dinner.",".$guest_id.");";
mysql_query($guest_dinner_query,$conn) or die(mysql_error());
}

下面是处理表单并执行上述函数的php代码:

<?php
include("functions.php");

$code = $_POST["code"];
$type = $_POST["type"];
$people = getPeople($code);
$ids = $people["ids"];
$email= "";

for($i = 0; $i < count($ids); $i++){
$response = $_POST["response_".$i];
$dinner = $_POST["dinner_".$i];
recordResponse($ids[$i],$response);
if($dinner != "null"){
recordDinner($ids[$i],$dinner);
}
if($type == 3){
$guest_responses = $_POST["guest_response_".$i];
$guest_fname = $_POST["guest_fname_".$i];
$guest_lname = $_POST["guest_lname_".$i];
$guest_dinner_response = $_POST["guest_dinner_response_".$i];
if($guest_dinner_response != "null"){
recordGuest($ids[$i],$guest_fname,$guest_lname,$guest_dinner_response);
}
}
}
?>

这是我的“访客”mysql 表的样子:

guest
id int auto inc (primary key)
fname varchar
lname varchar
person_id int

如有任何帮助,我们将不胜感激。

最佳答案

在尝试插入字符串值之前,用单引号将字符串括起来,即 'Bob'

关于php - 'Bob' 中的未知列 'field list' ... php 或 mysql 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3852134/

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