Php 未知列';提交时间109';在';字段列表';
我正在使用下面的PHP脚本进行一个我正在进行的实验,但是当它到达数字跨度任务(大约第110页)时,它似乎出现了错误消息:“字段列表中的未知列‘time_submit109’”。我如何解决这个错误(我对PHP不太精通,所以我很难调试它)。我认为错误与时间变量有关Php 未知列';提交时间109';在';字段列表';,php,mysql,Php,Mysql,我正在使用下面的PHP脚本进行一个我正在进行的实验,但是当它到达数字跨度任务(大约第110页)时,它似乎出现了错误消息:“字段列表中的未知列‘time_submit109’”。我如何解决这个错误(我对PHP不太精通,所以我很难调试它)。我认为错误与时间变量有关 <?php //counter for dynamic timestamp and next_page $counter_page = ++$counter+1; //connect to db server mysql_c
<?php
//counter for dynamic timestamp and next_page
$counter_page = ++$counter+1;
//connect to db server
mysql_connect($host,$user,$password) or die('Unable to connect to database server<br>'.mysql_error());
//if this is the first page of a survey
if (!isset ($identification))
//create db, if not already there
{
mysql_query("CREATE DATABASE IF NOT EXISTS $database");
}
//select db
mysql_select_db($database) or die('Unable to select database<br>'.mysql_error());
if (!isset ($identification))
{
//create table, if not already there
mysql_query ("CREATE TABLE $table (identification int(9) NOT NULL auto_increment,
page1 TEXT, participation_date DATE, time_submit1 VARCHAR(8), ip_number VARCHAR(15),
browser TINYTEXT, PRIMARY KEY (identification)) TYPE=MyISAM");
}
//change array, so that time_submit and page are renamed dynamically
foreach($variablen as $name=>$value)
{
if ($name == "next_page")
{
$name = "page".$counter_page;
}
elseif ($name == "counter")
{
$name = "time_submit".$counter;
$value = date("G:i:s");
}
$newarray2[$name]=$value;
}
$variablen = $newarray2;
//for each line in the array of submitted variables do the following (traverse array)
foreach($variablen as $name=>$value)
{
//modify table step by step (add colums according to html input)
mysql_query ("ALTER TABLE $table ADD $name VARCHAR(255)");
}
if (!isset ($identification))
{
//insert new record into db table (into the referer field) and thus generate identifcation (new record)
mysql_query("INSERT INTO $table (page1, participation_date, time_submit1, ip_number, browser)
VALUES ('$referer', '".date("Y-m-d")."', '".date("G:i:s")."',
'".$_SERVER['REMOTE_ADDR']."', '".$_SERVER['HTTP_USER_AGENT']."')")or die('Unable to insert into table!<br>'.mysql_error());
//grab last value of auto-increment variable "identification" to be used as identifier
$identification = mysql_insert_id();
}
//for each line in the array of submitted variables do the following
foreach($variablen as $name=>$value)
{
//update db table step by step
mysql_query("UPDATE $table SET $name='".mysql_real_escape_string($value)."' WHERE identification=$identification") or die('Unable to update table1<br>'.mysql_error());
}
//close connection
mysql_close();
//if this is the last html page: feedback for the participant
if (!isset ($next_page))
{
echo $thank_you_text;
}
//if questionnaire consists of still another html page
else
{
//call up next HTML page and pass on ID and counter
echo "<html><head></head><body onLoad=\"javascript:location.replace('".$next_page."?op56=".$identification."&nr93=".$counter."')\">
<a href=\"".$next_page."?op56=".$identification."&nr93=".$counter."\">Next Page</a></body></html>";
//manual forwarding
//echo "<html><head></head><body><a href=\"".$next_page."?op56=".$identification."&nr93=".$counter."\">Next Page</a></body></html>";
}
?>
不是真正的解决方案,但问题是您引用的字段名不是表的一部分。检查数组并确保表中确实存在字段名这是怎么回事?我试图把它缩小到我认为问题的地方。它一定与time_submit1变量及其更改方式有关?脚本完成后,您的表是什么样子的?什么是失败的查询?下面是表的外观()。我认为timesubmit查询用于生成新列?编辑:链接更改$variablelen
数组有多大?在我看来,您发出的SQL查询比您需要的多得多。您应该执行一次插入,而不是一次插入,然后执行几次更新。这将大大简化代码。我不确定,因为我没有编写PHP代码(由于它是TL:DR,所以删除了部分细节)。但这会导致这个问题吗?我想这实际上是在引导我走这条路。我很担心创建另一个专栏,因为我必须为后续的每一个专栏创建另一个专栏,但这让我发现根本原因可能是这个()。考虑到我的很多列都是varchar(255),你认为这可能是原因吗?如果是这样,我应该减少varchar计数吗?解决了这个问题!我将ALTER TABLE$TABLE ADD$name VARCHAR(255)更改为ALTER TABLE$TABLE ADD$name TEXT