当提交时,隐藏的输入拒绝发布表单

时间:2017-03-17 04:40:21

标签: php html mysql forms

我将数据库表格反映到管理信息中心的表格和表格中,因此我隐藏了表单输入,以便管理员无法看到它,但是当他点击两个提交按钮时(要将详细信息转发到电子邮件中,其次要从数据库中删除详细信息),它们都会提交到名为details.php的页面,但我使用ifelse语句来分隔按钮的功能。 / p>

我现在的问题是我无法找到表格中的故障,因为每次点击这些按钮时,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");
            }
            }
?>

1 个答案:

答案 0 :(得分:1)

您必须在第一个while循环中更改以下行:

$table = $tableName[0];

$table = $tableName['Tables_in_busybusi_link'];

无需在同一文件中始终包含连接文件。