PHP не отображается html - PullRequest
       0

PHP не отображается html

0 голосов
/ 20 апреля 2020

Я пытаюсь создать форум, и когда я нажимаю на кнопку topi c submit, чтобы перейти на эту страницу, нет текста с HTML дисплеев.

   //check for required fields from the form
   if ((!$_POST[topic_owner]) || (!$_POST[topic_title])
       || (!$_POST[post_text])) {
     header("Location: addtopic.html");
     exit;
 }

 //connect to server and select database
  $conn = mysql_connect("localhost", "name", "password")
      or die(mysql_error());
  mysql_select_db("forum",$conn) or die(mysql_error());

  //create and issue the first query
  $add_topic = "insert into forum_topics values ('', '$_POST[topic_title]',
      now(), '$_POST[topic_owner]')";
  mysql_query($add_topic,$conn) or die(mysql_error());

  //get the id of the last query
  $topic_id = mysql_insert_id();

 //create and issue the second query
  $add_post = "insert into forum_posts values ('', '$topic_id',
      '$_POST[post_text]', now(), '$_POST[topic_owner]')";
 mysql_query($add_post,$conn) or die(mysql_error());

  //create nice message for user
  $msg = "<P>The <strong>$topic_title</strong> topic has been created.</p>";
  ?>
  <html>
  <head>
  <title>New Topic Added</title>
  </head>
  <body>
  <h1>New Topic Added</h1>
  <?php print $msg; ?>
  </body>
  </html>

Я изменил mysql информация для входа и php работает на моем ноутбуке httpd server

это код страницы, которая переводит меня на php страницу

<html>
<head>
<title>Add a Topic</title>
</head>
<body>
<h1>Add a Topic</h1>
<form method=post action="do_addtopic.php">
<p><strong>Your E-Mail Address:</strong><br>
<input type="text" name="topic_owner" size=40 maxlength=150>
<p><strong>Topic Title:</strong><br>
 <input type="text" name="topic_title" size=40 maxlength=150>
<P><strong>Post Text:</strong><br>
<textarea name="post_text" rows=8 cols=40 wrap=virtual></textarea>
<P><input type="submit" name="submit" value="Add Topic"></p>
</form>
</body>
</html>

1 Ответ

0 голосов
/ 20 апреля 2020

Вероятно, потому что строка запроса неверна и не удалась, попробуйте изменить ее следующим образом:

//check for required fields from the form
   if (!$_POST['topic_owner'] || !$_POST['topic_title'])
       || !$_POST['post_text']) {
     header("Location: addtopic.html");
     exit;
 }

 //connect to server and select database
  $conn = mysql_connect("localhost", "name", "password")
      or die(mysql_error());
  mysql_select_db("forum",$conn) or die(mysql_error());

  //create and issue the first query
  $add_topic = "insert into forum_topics values ('', '{$_POST['topic_title']}',
      now(), '{$_POST['topic_owner']}')";
  mysql_query($add_topic,$conn) or die(mysql_error());

  //get the id of the last query
  $topic_id = mysql_insert_id();

 //create and issue the second query
  $add_post = "insert into forum_posts values ('', '$topic_id',
      '{$_POST['post_text']}', now(), '{$_POST['topic_owner']}')";
 mysql_query($add_post,$conn) or die(mysql_error());

  //create nice message for user
  $msg = "<P>The <strong>$topic_title</strong> topic has been created.</p>";
  ?>
  <html>
  <head>
  <title>New Topic Added</title>
  </head>
  <body>
  <h1>New Topic Added</h1>
  <?php print $msg; ?>
  </body>
  </html>

Дайте мне знать.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...