我正在尝试建立一个数据库,以便用户输入有关其姓名,体重,年龄等的信息。当用户单击“创建”按钮时,我希望页面不重定向,然后仅显示信息他们刚刚输入了我创建的表格。我该怎么做?
我正在尝试使用Header(Location: '');
函数,但是它给我一个错误。当前正在发生的事情是,当用户按下“创建”按钮时,它将重定向到一个新的空白页面,在该页面上将显示我要显示的所有信息。我想要的是页面不重定向而是仅更新表。我想使用PHP和HTML
<?php
if ( ! empty($_POST)) {
include 'dbh.inc.php';
$mysqli = new mysqli('localhost','root','','exerdata');
if ($mysqli->connect_error) {
die('Connect Error: '.$mysqli->connect_errno . ': ' . $mysqli->connect_error );
}
$sql = "INSERT INTO updatedexercisedata ( exername,exerweight,exerpart,exerreps,exersets,exertime ) VALUES ( '{$mysqli->real_escape_string($_POST['ExerName'])}', '{$mysqli->real_escape_string($_POST['ExerWeight'])}', '{$mysqli->real_escape_string($_POST['ExerPart'])}', '{$mysqli->real_escape_string($_POST['ExerReps'])}', '{$mysqli->real_escape_string($_POST['ExerSets'])}', '{$mysqli->real_escape_string($_POST['ExerTime'])}' )";
$insert = $mysqli->query($sql);
if( $insert ) {
$sqlpublish = "SELECT * FROM updatedexercisedata;";
$publishresult = mysqli_query($connec, $sqlpublish);
$resultcheck = mysqli_num_rows($publishresult);
if ($resultcheck > 0) {
while ($publishrow = mysqli_fetch_assoc($publishresult)) {
echo "<tr class='name_row'><th>" . $publishrow["exername"] ."</th><th>" .$publishrow["exerweight"] ."</th><th>" .$publishrow["exerpart"] ."</th><th>" .$publishrow["exerreps"] ."</th><th>" .$publishrow["exersets"] ."</th><th>" .$publishrow["exertime"] ."</th></tr>";
echo "Success! Row ID: {$mysqli->insert_id}";
}
}
} else {
die("Error: {$mysqli->errno} : {$mysqli->error}");
}
$mysqli->close();
}
在这种类型的问题中没有功能错误,但是有逻辑错误。如前所述,我不希望代码将它们重定向到新页面,这就是我尝试echo "<tr class='name_row'><th>" . $publishrow["exername"] ."</th><th>" .$publishrow["exerweight"] ."</th><th>" .$publishrow["exerpart"] ."</th><th>" .$publishrow["exerreps"] ."</th><th>" .$publishrow["exersets"] ."</th><th>" .$publishrow["exertime"] ."</th></tr>";