简体   繁体   English

PHP代码输入我的HTML

[英]php code entering my html

I'm trying to insert data from a php page into my mySQL databse. 我试图将数据从php页面插入到mySQL数据库中。 when I refresh the page parts of my php code is being displayed on the page rather than being processed below is my code(sensitive info blocked): 当我刷新页面时,我的PHP代码的一部分显示在页面上,而不是在下面进行处理,这是我的代码(敏感信息被阻止):

<?php
  $servername = "localhost";
  $username = "*******";
  $password = "*******";
  $dbname = "accounts";

  // Create connection
  $conn = mysqli_connect($servername, $username, $password, $dbname);
  // Check connection
  if (!$conn) {
      die("Connection failed: " . mysqli_connect_error());
  }

  $sql = "INSERT INTO MyGuests (firstname, lastname, email)
  VALUES ('John', 'Doe', 'john@example.com')";

  if (mysqli_query($conn, $sql)) {
  echo "New record created successfully";
  } else {
     echo "Error: " . $sql . "<br>" . mysqli_error($conn);
  }

  mysqli_close($conn);
?>

and this is a screenshot of the "view source", as you can see it sort of stops doing it's PHP and displaying into my page. 这是“查看源代码”的屏幕截图,您可以看到它停止了使用PHP并显示在我的页面中的过程。 thoughts? 有什么想法吗?

查看源

Hello bro your code is alright i test it on my local server. 您好兄弟,您的代码还不错,我在本地服务器上对其进行了测试。 i think you are not saving file with correct extension. 我认为您没有以正确的扩展名保存文件。 or your mysql table fields are incorrect if data is not inserting. 如果没有插入数据,则您的mysql表字段不正确。 Correct extension for php file name.php php文件名.php的正确扩展名

我认为您的Web服务器文件扩展名存在问题,请确保您的Web服务器处于活动状态并且文件扩展名为.php。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM