Daniel C.
Daniel C.

Reputation: 59

Hidden input refuses to post form when submited

I echoed out my database tables into a table and a form in the admin dashboard, so i hide the form inputs so that the admin doesn't get to see it but when he clicks on the two submit buttons(One to forward details into email and second to delete details from database), both of them submits to a page called details.php but i used the if and else statements to separate the functionalities of the buttons.

My problem now is i cant locate what the hitch is with the form because each time any of these buttons are clicked the details.php page opens up a plainly white page; nothing happens. I am so sure i have thoroughly checked my codes to locate what the problem really is but to no avail; i removed the delete details from the details.php page but the forward details wont work still, i place the details.php code above in the admins dashboard, yet that wont work either. I hope someone could help me out. here is my code:

Database Connection:

<?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());
?>

Tables Echoed Out into hidden forms:

<?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 page:

<?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 = "[email protected]";
$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");
            }
            }
?>

Upvotes: 1

Views: 87

Answers (1)

Ankit Singh
Ankit Singh

Reputation: 1477

You have to just change the following line in your first while loop:

$table = $tableName[0];

to

$table = $tableName['Tables_in_busybusi_link'];

There is no need to include connection file all the time in same file.

Upvotes: 1

Related Questions