Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/227.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.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 更新:连接MySQL数据库时出现文章ID错误_Php_Mysqli - Fatal编程技术网

Php 更新:连接MySQL数据库时出现文章ID错误

Php 更新:连接MySQL数据库时出现文章ID错误,php,mysqli,Php,Mysqli,我正在创建一个允许将评论发布到本地主机服务器的电子邮件表单 我有三个PHP文件: page1.php和page2.php包含表单并显示注释 manage_comments.php包含将表单连接到服务器的代码 我遇到问题的地方是manage_comments.php文件。提交表单后,我收到了一个错误代码 错误代码:1193无效的项目id 文章id指的是page1.php和page2.php的id,分别为“1”和“2” mywebsite.com/page1.php?id=1, mywebsit

我正在创建一个允许将评论发布到本地主机服务器的电子邮件表单

我有三个PHP文件:

  • page1.php
    page2.php
    包含表单并显示注释
  • manage_comments.php
    包含将表单连接到服务器的代码
我遇到问题的地方是
manage_comments.php
文件。提交表单后,我收到了一个错误代码

错误代码:1193无效的项目id

文章id指的是
page1.php
page2.php
的id,分别为“1”和“2”

mywebsite.com/page1.php?id=1, mywebsite.com/page2.php?id=2
在表单的教程中,我被指示编写一个隐藏值来保存文章的id

<form>
    <input type='hidden' name='articleid' id='articleid' value='<? echo $_GET["id"]; ?> />
</form>

我更改了代码,但仍然收到1193错误。该教程是在“mysqli”之前编写的,我必须将代码从mysql转换为mysqli。以下是manage_comments.php中的代码:

      <?

      if( $_POST )
      {

      $mysqli = new mysqli('localhost', 'sosdeff', 'edflash9', 'sosdeff_testerforms');

      /* check connection */
      if (mysqli_connect_errno()) {
      printf("Connect failed: %s\n", mysqli_connect_error());
      exit();
      }

      if (!mysqli_query($mysqli, "SET a=1")) {
      printf("Errorcode: %d\n", mysqli_errno($mysqli));
      }

      mysqli_select_db($mysqli, "sosdeff_testerforms");

      $users_name = $_POST['name'];
      $users_email = $_POST['email'];
      $users_website = $_POST['website'];
      $users_comment = $_POST['comment'];

      $users_name = mysqli_real_escape_string($mysqli, $users_name);
      $users_email = mysqli_real_escape_string($mysqli, $users_email);
      $users_website = mysqli_real_escape_string($mysqli, $users_website);
      $users_comment = mysqli_real_escape_string($mysqli, $users_comment);

      $articleid = $_GET['articleid'];

      if( ! is_numeric($articleid) )

      die('invalid article id');

      $query = "INSERT INTO `sosdeff_testerforms`,`comments` (`id`, `name`, `email`, `website`, `comment`, `timestamp`, `articleid`)

     mysqli_query($query);
     echo "<h2>Thank you for your Comment!</h2>";
     mysqli_close($mysqli);

     }
     ?>

在表单中,该字段称为
articleid

提交表单后,id为空,因为表单中没有
id
字段,只有
articleid

manage_comments.php
中,将代码更改为:

$articleid = $_GET['articleid'];

if( ! is_numeric($articleid) )
    die('invalid article id'); 

value='
请确保打开了open short标记,否则请执行
value='
另外,您缺少一个引号。感谢您的回复。好吧,你说的开放式短标签是什么意思?不客气。在PHP中,这个

$articleid = $_GET['articleid'];

if( ! is_numeric($articleid) )
    die('invalid article id');