gpt4 book ai didi

php - mysql脚本仅重新加载

转载 作者:行者123 更新时间:2023-11-29 19:27:31 25 4
gpt4 key购买 nike

如果我单击“提交”,它只会刷新网站。 connect.php 是正确的。但一定有什么地方是不正确的。

in.php

<form id="mathe1" action="script.php" method="post">
<input name="nummer" type="number" value=""/><br><br>
<label id="label"><p>Hausübung</p></label>
<textarea name="hu" cols="60" rows="5"></textarea><br><br>
<input name="Submit1" type="submit" value="Senden"/>
</from>

脚本.php:

<?php    
include('include/connect.php');

$nummer = $_POST['nummer'];
$hu = $_POST['hu'];
$db = "hu";

if (empty($nummer)) {
header('Location:in.php');
}
if (empty($hu)) {
header('Location:in.php');
}
else {
$sql = "INSERT INTO $db VALUES ('$nummer','$hu')";
$query = mysql_query($sql);
}
?>

最佳答案

看来您定义了错误的 if 语句,并且位置应该绝对定义,因此:

在 include/connect.php

  $mysqli = new mysqli('sqlhost', 'user', 'password', 'db');

在 scpipt.php

  $nummer = $_POST['nummer'];
$hu = $_POST['hu'];
$table = "hu";
$url = "http://yourdevhost/in.php";

if (empty($nummer) || empty($hu)) {
header('Location: '.$url);
} else {
$stmt = $mysqli->prepare('INSERT INTO ? VALUES (?, ?)');
$stmt->bind_param('sss', $table, $nummer, $hu);
$stmt->execute();
}

关于php - mysql脚本仅重新加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42029753/

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