我将我的数据库表回显到管理仪表板中的一个表和一个表单中,所以我隐藏了表单输入,这样管理员就看不到它,但是当他点击两个提交按钮时(一个转发详细信息到电子邮件中,然后从数据库中删除详细信息),它们都提交到一个名为 details.php 的页面,但我使用 if
和 else
语句来分离功能按钮。
我现在的问题是我无法找到表单的问题所在,因为每次单击这些按钮中的任何一个时,details.php 页面都会打开一个纯白的页面;什么都没发生。我非常确定我已经彻底检查了我的代码以找出真正的问题所在,但无济于事;我从 details.php 页面中删除了删除详细信息,但转发详细信息仍然不起作用,我将上面的 details.php 代码放在管理员仪表板中,但这也不起作用。我希望有人能帮助我。这是我的代码:
数据库连接:
<?php
$serverName="localhost";
$dbusername="busybusi_link_u";
$dbpassword="shatter1";
$dbname="busybusi_link";
mysql_connect($serverName,$dbusername,$dbpassword)/* or die('the website is down for maintainance')*/;
mysql_select_db($dbname) or die(mysql_error());
?>
表格回显到隐藏表格中:
<?php
include '_inc/dbconn.php';
$result = mysql_query("SHOW TABLES WHERE `Tables_in_busybusi_link` NOT LIKE 'admin'");
while($tableName = mysql_fetch_row($result)) {
$table = $tableName[0];
echo '<h1>'.$table.'';
echo "<a href='drop_table.php?table=".$table."'> <font color=\"#ff0000\"><i class=\"fa fa-times\"></i></font></a></h1>";
echo '<hr class=" hr_color hrmargin_b_30"/>';
echo '<div class="wpcf7" id="wpcf7-f21-p31-o1" lang="en-US" dir="ltr">';
echo '<div class="screen-reader-response"></div>';
echo '<table>';
echo '<thead>';
echo '<tr><th>Location</th><th>Email</th><th>Action</th><th>Action</th></tr>';
echo '<tbody><tr><form method="post" action="details.php" >';
include '_inc/dbconn.php';
$query1=mysql_query("SELECT * FROM $table ");
while($query2=mysql_fetch_array($query1)){
echo "\<td>".$query2['location']."<input type=\"hidden\" name=\"id\" value=".$query2['id']."><input type=\"hidden\" name=\"location\" value=".$query2['location']."></td>
<td>".$query2['email']."<input type=\"hidden\" name=\"email\" value=".$query2['email']."><input type=\"hidden\" name=\"age\" value=".$query2['age']."></td>
<td><button type=\"submit\" name=\"forward_details\" class=\"wpcf7-form-control wpcf7-submit\" >Forward Details <i class=\"fa fa-mail-forward\"></i></button></td>
<td><button type=\"submit\" name=\"delete_details\" class=\"wpcf7-form-control wpcf7-submit\" >Delete Details <i class=\"fa fa-times\"></i></button></td>\n";
}
echo '</form></tr>';
echo '</tbody>';
echo '</table>';
echo '</div>';
}
?>
Details.php页面:
<?php
session_start();
include '_inc/dbconn.php';
if(!isset($_SESSION['admin_login']))
header('location:index.php');
?>
<?php
if($_POST['forward_details']){
include '_inc/dbconn.php';
$sql="SELECT * FROM admin WHERE id='1'";
$result=mysql_query($sql);
$rws= mysql_fetch_array($result);
$email = $_POST['email'];
$age = $_POST['age'];
$location = $_POST['location'];
$EmailTo = $rws[3];
$EmailFrom = "Admin@busybusinesshub.online";
$Subject = "Client Details";
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Location: ";
$Body .= $location;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $email;
$Body .= "\n";
$Body .= "Age: ";
$Body .= $age;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
if ($success){
//Email Forward Success Msg
$msg = "<i class=\"fa fa-check\"></i> Details Has Been Successfully Sent To System Email";
header("Location:admin_dashboard.php?msg=$msg");
}else{
//Email Forward Error Msg
$msge = "<i class=\"fa fa-exclamation-circle\"></i> Details Was Not Sent, Please Check That System Email Is Correctly Written";
header("Location:admin_dashboard.php?msge=$msge");
}
}else if($_POST['delete_details']){
$id= mysql_real_escape_string($_REQUEST['id']);
$email= mysql_real_escape_string($_REQUEST['email']);
$sql = "DELETE FROM $email WHERE id = '$id' " ;
$deleted = mysql_query( $sql );
if(! $deleted ) {
//Data Delete Error Msg
$msge = "<i class=\"fa fa-exclamation-circle\"></i> For Some Reason, Details Could Not Be Deleted!";
header("Location:admin_dashboard.php?msge=$msge");
}else{
//Data Delete Success Msg
$msg = "<i class=\"fa fa-check\"></i> Details Successfully Deleted";
header("Location:admin_dashboard.php?msg=$msg");
}
}
?>
最佳答案
您只需在第一个 while 循环中更改以下行:
$table = $tableName[0];
到
$table = $tableName['Tables_in_busybusi_link'];
不需要一直在同一个文件中包含连接文件。
关于php - 隐藏输入在提交时拒绝发布表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42849336/