gpt4 book ai didi

php - php中的href html按钮

转载 作者:搜寻专家 更新时间:2023-10-31 22:19:59 25 4
gpt4 key购买 nike

我正在尝试在提交表单后出现的 .php 文件中放置一个按钮 [将重定向到主页]。

php文件是这样的:

<?php 

$user = 'root';
$pass = '';
$db = 'testdb';

header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");

$conn = new mysqli('localhost', $user, $pass, $db) or die("Unable to connect.");

$sql = "INSERT INTO Customers (CompanyName, City, Country) VALUES ('$_POST[post_company]', '$_POST[post_city]', '$_POST[post_country]')";

if(mysqli_query($conn, $sql)){
echo "New record created successfully!";
$last_id = $conn->insert_id;
echo "\nNew record has ID: " . $last_id;
}else{
echo "Error 1: " . $sql . "<br>" .mysqli_error($conn);
}


// echo("<button onclick='location.href='index.html'>Back to Home</button>");
// this is a test I did before and didn't work

$conn->close();

?>

<div id="center_button"><button onclick="location.href='index.html'">Back to Home</button></div>

我试过将其制作成 .html 文件并放入 php 代码中,但没有成功。
我看到你可以将html代码放在一个php文件中,但这似乎也不起作用。我也尝试过不使用 div 标签,也尝试过放置 html 和 body 标签。
顺便说一句,数据库工作正常,它更新正常,我似乎无法显示 html 代码。


我做错了什么?

最佳答案

您缺少 HTML 标记。这就是为什么您看不到按钮的原因。

?>
<html>
<head>
</head>

<body>
<div id="center_button">
<button onclick="location.href='index.html'">Back to Home</button>
</div>
</body>
</html>

编辑:删除这一行:

header("Content-Type: application/json; charset=UTF-8");

关于php - php中的href html按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30427891/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com