我在将数据从表单发送到函数时遇到了一些问题
这是我的表格:
echo "<form id='AddCompany' action='' method=post>";
echo "<table>";
echo "<tr>";
echo "<th colspan='2'>Opret nyt firma</th>";
echo "</tr>";
echo "<td>Firma Navn:<td><input type='text' name='Name' /></td>";
echo "</td></tr>";
echo "<td>Adresse:<td><input type='text' name='Address' /></td>";
echo "</td></tr>";
echo "<td>Postnr.:<td><input type='text' name='Zipcode' /></td>";
echo "</td></tr>";
echo "<td>By:<td><input type='text' name='City' /></td>";
echo "</td></tr>";
echo "<td>Land:<td><input type='text' name='Country' /></td>";
echo "</td></tr>";
echo "<td>Tlf:<td><input type='text' name='Phone' /></td>";
echo "</td></tr>";
echo "<td>Slogan:<td><input type='text' name='Slogan' /></td>";
echo "</td></tr>";
echo "<td>Catch All Email:<td><input type='text' name='Email' /></td>";
echo "</td></tr>";
echo "<td>Logo 1:<td><input type='FILE' name='Logo1' /></td>";
echo "</td></tr>";
echo "<td>Lille Logo:<td><input type='FILE' name='SmallLogo' /></td>";
echo "</td></tr>";
echo "<td>Logo 2:<td><input type='FILE' name='Logo2' /></td>";
echo "</td></tr>";
echo "<td colspan='2'><input type='submit' value='Opret Firma' />";
echo "</form>";
echo "</td></tr>";
echo "</tr>";
echo "</table>";
我想将数据发送到这个函数
function insertRecord ($fieldarray)
{
$this->errors = array();
global $dbconnect, $query;
$dbconnect = db_connect($this->dbname) or trigger_error("SQL", E_USER_ERROR);
$fieldlist = $this->fieldlist;
foreach ($fieldarray as $field => $fieldvalue) {
if (!in_array($field, $fieldlist)) {
unset ($fieldarray[$field]);
} // if
} // foreach
$query = "INSERT INTO $this->tablename SET ";
foreach ($fieldarray as $item => $value) {
$query .= "$item='$value', ";
} // foreach
$query = rtrim($query, ', ');
return;
} // insertRecord
我刚刚意识到您可能还需要这段代码:
class Company extends Default_Table
{
// additional class variables go here
function __construct ()
{
$this->tablename = 'Company';
$this->dbname = 'oop';
$this->rows_per_page = 15;
$this->fieldlist = array('ID', 'Name', 'Address','Zipcode','City','Country','Phone','Slogan','CatchAllEmail','Logo1','LogoSmall','Logo2');
$this->fieldlist['ID'] = array('pkey' => 'y');
} // __construct
} // Company
我在哪里调用该函数以及我应该发送哪些变量?
我试过onclick=insertRecord()
似乎不起作用,我想这是因为我需要插入一个变量,我认为它需要是表单数据的数组,因为函数是用数组声明的。
正如你所看到的,我对此非常敏感。
我发现了以下内容:
如果我在 insertRecord 函数中的 foreach 循环之后回显我的 $query,我会看到如下查询: INSERT INTO Company SET Name='1', Address='2', Zipcode='3', City='4', Country ='5',电话='6',口号='7',CatchAllEmail='8',Logo1='',LogoSmall='',Logo2=''
但是仍然没有插入任何内容,我已经在 2 台服务器上尝试过此操作,并且我知道用户具有插入权限,但是没有插入任何内容。