Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/245.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在数据库中添加新记录时出错_Php_Database_Forms_Mysqli - Fatal编程技术网

Php 在数据库中添加新记录时出错

Php 在数据库中添加新记录时出错,php,database,forms,mysqli,Php,Database,Forms,Mysqli,我发现了一个非常好的代码,可以在这个网站上添加和修改记录: 当我想添加新记录时,屏幕上出现以下错误: 错误:无法准备SQL语句 错误在下面第43行附近 1 NEW RECORD 2 3 */ 4 // if the 'id' variable is not set in the URL, we must be creating a new record 5 else 6 { 7 // if the form's submit butto

我发现了一个非常好的代码,可以在这个网站上添加和修改记录:

当我想添加新记录时,屏幕上出现以下错误:

错误:无法准备SQL语句

错误在下面第43行附近

1           NEW RECORD
2
3        */
4   // if the 'id' variable is not set in the URL, we must be creating a new record
5   else
6   {
7       // if the form's submit button is clicked, we need to process the form
8       if (isset($_POST['submit']))
9       {
10          // get the form data
11              $titel = htmlentities($_POST['titel'], ENT_QUOTES);
12              $datum = htmlentities($_POST['datum'], ENT_QUOTES);
13              $omschrijving = htmlentities($_POST['omschrijving'], ENT_QUOTES);
14              $begin = htmlentities($_POST['begin'], ENT_QUOTES);
15              $eind = htmlentities($_POST['eind'], ENT_QUOTES);
16          
17          // check that firstname and lastname are both not empty
18          if ($titel == '' || $datum == '' || $omschrijving == '' || $begin == '' || 
19  $eind == '')
20          {
21              // if they are empty, show an error message and display the form
22              $error = 'ERROR: Please fill in all required fields!';
23              renderForm($titel == '' || $datum == '' || $omschrijving == '' || $begin == 24 '' || $eind == '');
25          }
26          else
27          {
28              // insert the new record into the database
29              if ($stmt = $mysqli->prepare("INSERT famevents (titel, datum, omschrijving, 30 begin, eind) VALUES (?, ?)"))
31              {
32                  $stmt->bind_param("ss", $titel, $datum, $omschrijving, $begin, $eind);
33                  $stmt->execute();
34                  $stmt->close();
35              }
36              // show an error if the query has an error
37              else
38              {
39                  echo "ERROR: Could not prepare SQL statement.";
40              }
41              
42              // redirec the user
43              header("Location: beheerevents.php");
44          }
45          
46      }
47      // if the form hasn't been submitted yet, show the form
48      else
49      {
50          renderForm();
51      }
52  }
53  
54  // close the mysqli connection
55  $mysqli->close();
就我个人而言,我看不出我在这里做错了什么,也看不出哪里出了问题

在这段代码中还有一个$\u会话将检查是否有人登录是或否

我在做什么:

1。将代码修改为我需要从数据库获取或发送到的数据

2。我试图首先让
中工作,但我做不到,所以我将它改回了文本输入。到目前为止,我仍然希望看到能够使用我所拥有的代码

3.然后我发现我忘记了在数据库表中添加新记录的部分修改代码,就像上面代码的编辑部分一样


之后,错误出现在我的屏幕上。。。。。我有点被困在如何解决这个问题上。。。 希望您能帮我解决这个问题。

语句中的错误“INTO”关键字丢失:

prepare("INSERT INTO famevents (titel, datum, omschrijving, 30 begin, eind) VALUES (?, ?)"))

所以您只是得到了
echo“错误:无法准备SQL语句。”。这是你应该找的。在那里打印出
$stmt->error()
。它将告诉您SQL参数计数不匹配的情况在第200行的/public/sites/www.josdenhertog.nl/familiedenhertog/admin/famevents/records.php中的非对象上,可能是因为我有一个在后台运行的会话,用于检查管理员是否是网站的成员?Em,然后使用
$mysqli->
。好的,现在它显示以下内容:错误:列计数与第1行的值计数不匹配。警告:无法修改标题信息-标题已由(输出开始于/public/sites/www.josdenhertog.nl/familiedenhertog/admin/famevents/records.php:201)在/public/sites/www.josdenhertog.nl/familiedenhertog/admin/famevents/records.php第206行发送。第一句有效。你读了吗?您看过SQL查询了吗?