Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.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数据库?_Php_Html_Mysql_Sql - Fatal编程技术网

Php 为什么评论没有上传到MySQL数据库?

Php 为什么评论没有上传到MySQL数据库?,php,html,mysql,sql,Php,Html,Mysql,Sql,我有一个允许用户上传文件和提交评论的网页。然后,应该将文件和相应的注释输入到MySQL数据库中。目前,如果有人试图这样做,文件将被上传,链接将按原样插入数据库。但是,注释从未输入到数据库中。该网页的代码如下: <div style="padding-left: 225px; padding-top: 15px; padding-bottom: 15px; background-color: #754f00; border-style: solid; border-weight: 4px;

我有一个允许用户上传文件和提交评论的网页。然后,应该将文件和相应的注释输入到MySQL数据库中。目前,如果有人试图这样做,文件将被上传,链接将按原样插入数据库。但是,注释从未输入到数据库中。该网页的代码如下:

<div style="padding-left: 225px; padding-top: 15px; padding-bottom: 15px; background-color: #754f00; border-style: solid; border-weight: 4px; border-color: black;">

<div class="uploadbox"  style='margin-left: 100px'>

<? include('uploadform.php') ?>
<? include('uploader.php'); ?>


</div>

<center>
<? include('testpost.php'); ?>
</center>

</div>


<br>
<hr>
<br>


<center>

<? include('feed.php'); ?>

</center>




其中uploadform.php文件由

<form enctype="multipart/form-data" method="POST">

    Comment:<br />
    <textarea name='comment' id='comment'></textarea><br />

    <input type="hidden" name="MAX_FILE_SIZE" value="10000000" />

    Choose a file to upload: <input name="uploadedfile" type="file" /><br />

    <input type="submit" value="Submit" />


</form>

评论:

选择要上载的文件:
uploader.php文件包含以下内容:

<?php

if( $_POST ){
// Where the file is going to be placed 
$target_path = "uploads/";

/* Add the original filename to our target path.  
Result is "uploads/filename.extension" */
$target_path = $target_path .time() .basename( $_FILES['uploadedfile']['name']);

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The  <a href=" . $target_path . ">file</a> has been uploaded! <br /> LINK: " . $target_path;

  $con = mysql_connect("localhost","theshitp_user","password");

  if (!$con)
  {
    die('Could not connect: ' . mysql_error());
  }

  mysql_select_db("theshitp_posts", $con);

  $query = "
  INSERT INTO `theshitp_posts`.`test2` (`file`) VALUES ( '$target_path' );";

  mysql_query($query);

  echo "<p style='color: grey;'><b>Thank you for your Comment!</b></p>";

  mysql_close($con);


} else{
    echo "There was an error uploading the file, please try again!";
}

}

?>

您试图在必须是主键的“id”中插入Null,因此此查询不起作用,您需要更正它。请参阅-

您试图在必须是主键的“id”中插入Null,因此此查询不起作用,您需要更正它。请参阅-

查看testpost.php文件中的查询参数-->


查询参数中的第一个分号是删除这个内部“;”第一个$query=“;” 查看testpost.php文件中的查询参数-->



查询参数中的第一个分号是删除这个内部“;”第一个$query=“;”;请尝试$users\u comment,而不是“$users\u comment”。谢谢您的回复。不幸的是,我已经尝试过改变;它不起作用。print$\u POST['comment']-如果你能看到文本,请告诉我,我已经这样做了。注释是使用该代码打印的。注释掉这一行,然后看看会发生什么$users\u comment=mysql\u real\u escape\u string($users\u comment);请尝试$users\u comment,而不是“$users\u comment”。谢谢您的回复。不幸的是,我已经尝试过改变;它不起作用。print$\u POST['comment']-如果你能看到文本,请告诉我,我已经这样做了。注释是使用该代码打印的。注释掉这一行,然后看看会发生什么$users\u comment=mysql\u real\u escape\u string($users\u comment);我将尝试用空白条目替换NULL。你在哪里看到一个小男孩;在查询中?最后?是的,最后在testpost.php的$query=“;”内,谢谢,这很有效。剩下的唯一问题是,它创建了两个独立的数据库条目:一个包含文件链接和注释的空白条目,另一个包含文件链接的空条目和注释的正确条目。你知道如何在数据库的一行而不是两行中获取所有这些数据吗?因此,你必须执行更新操作,而不是第二次插入到表中,第二次插入将在表中创建新行。。你明白了吗?因此,在使用mysql\u insert\u ID()插入文件名行时,请将您的ID放在手边。。。并使用该ID更新行..将testpost.php中的$query更改为`$query=“update theshitp\u posts.test2 SET comment=$comment,timestamp=CURRENT\u timestamp(),其中ID=“.ID`我将尝试用空白条目替换NULL。你在哪里看到一个小男孩;在查询中?最后?是的,最后在testpost.php的$query=“;”内,谢谢,这很有效。剩下的唯一问题是,它创建了两个独立的数据库条目:一个包含文件链接和注释的空白条目,另一个包含文件链接的空条目和注释的正确条目。你知道如何在数据库的一行而不是两行中获取所有这些数据吗?因此,你必须执行更新操作,而不是第二次插入到表中,第二次插入将在表中创建新行。。你明白了吗?因此,在使用mysql\u insert\u ID()插入文件名行时,请将您的ID放在手边。。。并使用该ID更新行..将testpost.php中的$query更改为`$query=“update theshitp\u posts.test2 SET comment=$comment,timestamp=CURRENT\u timestamp(),其中ID=“.ID`
<?
if( $_POST )
{
  $con = mysql_connect("localhost","theshitp_user","password");

  if (!$con)
  {
    die('Could not connect: ' . mysql_error());
  }

  mysql_select_db("theshitp_posts", $con);

  $users_comment = $_POST['comment'];

  $users_comment = mysql_real_escape_string($users_comment);

  $query = "
  INSERT INTO `theshitp_posts`.`test2` (`id`, `comment`, `timestamp`) VALUES (NULL, '$users_comment', CURRENT_TIMESTAMP() );";

  mysql_query($query);

  echo "<p style='color: grey;'><b>Thank you for your Comment!</b></p>";

  mysql_close($con);
}
?>
$query = "
  INSERT INTO `theshitp_posts`.`test2` (`id`, `comment`, `timestamp`) VALUES (NULL, '$users_comment', CURRENT_TIMESTAMP() );";
$query = " INSERT INTO `theshitp_posts`.`test2` (`id`, `comment`, `timestamp`) VALUES ('', '$users_comment', CURRENT_TIMESTAMP() )";