Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/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错误,找不到位置_Php - Fatal编程技术网

Php错误,找不到位置

Php错误,找不到位置,php,Php,我有这个文件,我需要帮助修复我得到的错误。我检查了一下,看起来不错,但一定是出了什么问题。错误是 Notice: Undefined index: name in /home/info130/FA13/users/tmh233fa13/www/Test/posting_wall.php on line 62 下面列出了我的php,两个文件 谢谢 发布_wall.php文件 <!DOCTYPE HTML> <html> <head> <link t

我有这个文件,我需要帮助修复我得到的错误。我检查了一下,看起来不错,但一定是出了什么问题。错误是

Notice: Undefined index: name in /home/info130/FA13/users/tmh233fa13/www/Test/posting_wall.php on line 62
下面列出了我的php,两个文件

谢谢

发布_wall.php文件

   <!DOCTYPE HTML>
<html>
<head>
<link type="text/css" rel="stylesheet" href="post.css" />

<meta name="viewport" content="width=device-width" />
<title>Daily Dorm News</title>
</head>

<body>
<?php 
/* [INFO/CS 1300 Project 3] index.php 
 * Main page for our app.
 * Shows all previous posts and highlights the current user's post, if any.
 * Includes a link to form.php if user wishes to create and submit a post.
 */ 

require('wall_database.php');

// Fetching data from the request sent by form.php  

$name = $_REQUEST['name'];

$is_valid_post = true;
// Checking if a form was submitted
if (isset($_REQUEST['name'])){
  // Fetching data from the request sent by form.php  
$name = strip_tags($_REQUEST['name']);
$email = strip_tags($_REQUEST['email']);
$message = strip_tags($_REQUEST['message']); 
$date = strip_tags($_REQUEST['date']);  
  // Saving the current post, if a form was submitted
  $post_fields = array();
  $post_fields['name'] = $name;
  $post_fields['email'] = $email;
  $post_fields['message'] = $message;
  $post_fields['date'] = $date;

  $success_flag = saveCurrentPost($post_fields);
}

//Fetching all posts from the database
$posts_array = getAllPosts();

require('header.php');
?>
    <p><a href="form.php">Submit a Post</a></p>

    <?php
    if(isset($name)) {
      echo "<h3>Thanks ".$name." for submitting your post.</h3>";
    }
    ?>

    <p>Here are all the posts we have received.</p>
    <ul id="posts_list">
    <?php 

    // Looping through all the posts in posts_array
    $counter = 1;
    foreach(array_reverse($posts_array) as $post){
      $name = $post['name'];
      $email = $post['email'];
      $message = $post['message'];
      $date = $post['date'];
      if ($counter % 2==1)
        $li_class = "float-left";
      else
        $li_class = "float-right";

      echo '<li class="'.$li_class.'"><h3><span>'.$name.'</span> wrote a post.</h3></li>';
      // Add more details here
    }
    ?>
    </ul>
  </div>

</body>
</html>

每日宿舍新闻

这意味着HTTP POST缺少“name”键


错误是明确的,如果您编辑php文件并转到第62行,您可以理解。

您从未设置$name,而是设置了$username

从您的代码中复制和剪裁:


是的,我这样做了,因为在我的表单中,用户名字段的名称=name,或者这不重要?你从未设置可变$name我尝试过,但运气不好,不确定,这是一个简单的修复我只是有点迷路。我将OP中的代码更新为我尝试过的代码,但仍然没有成功
<!DOCTYPE HTML>
<html> 
<head>

<link type="text/css" rel="stylesheet" href="index.css" />
<meta name="viewport" content="width=device-width" />
<title>Daily Dorm News</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<script>
$(function() {
$( "#datepicker" ).datepicker();
$('form').submit(function (e) {
    var value;

    // "message" pattern : from 3 to 15 alphanumerical chars

    value = $('[name="message"]').val();
    if (!/^[A-Za-z0-9]{3,15}$/.test(value)) {
        alert('Wrong value for "message".');
        e.preventDefault();
        return;
    }

    // "name" pattern : at least 1 digit

    value = $('[name="name"]').val();
    if (!/\d+/.test(value)) {
        alert('Wrong value for "name".');
        e.preventDefault();
        return;
    }
});

});
</script>

</head>
<body>
<h1> <u>Daily Dorm News</u> <br> The best place to get your latest Dorm news </h1>
<form action="posting_wall.php" method="get">
<div id="container">
Name:<input type="text" name="name" pattern="[A-Za-z0-9]{3,15}" title="Letters and numbers only, length 3 to 15" required autofocus><br>
E-mail: <input type="email" name="email" maxlength="20" required><br>

Post:<br>

<textarea rows="15" cols="50" name='message'></textarea>
</div>
Date this event took place: <input type="text" name='date' id="datepicker" required> <br>
<input type="reset" value="Reset">
<input type="submit">
</form>
<p><a href="posting_wall.php">Posting Wall</a></p>
</body>
</html>
$username = strip_tags($_REQUEST['name']);

...

$post_fields['username'] = $name;