1

im performing search from the database and displaying the result in the checkbox format in which when i select the checkbox the respectively values should be inserted in the another table which is in (a.php) since the search result have multiple values im storing the values in array but when im trying print the array with echo $_POST['friend']; it showing result as "Array" anyone help me how can i display the variables stored in array

<form method="post">
<div class="form-group">
    Name
    <br/>
    <input type="text" class="form-control" name="name"  />
    </div>
    <div class="form-group">
   Email <br/>
   <input type="text" class="form-control"name ="email"  />
   </div>
   <div class="form-group">
    Qualification<br/>
    <input type="text" class="form-control" name ="qualify" />
    </div>
    <input type="submit" value="Search" />

</form>
<?php
 $servername = "localhost";
$username = "root";
$password = "root";
$dbname = "myDB";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
   $name=$_POST['name'];
 $email=$_POST['email'];
   $qualification=$_POST['qualify'];
 $sql = "SELECT * FROM form WHERE Name ='$name' OR EmailAddress = '$email' OR Qualification = '$qualification' ";
 $result=$conn->query($sql);

 if(!empty($_POST)) {
    if($result->num_rows === 0) 
{
  echo '<p style="margin-left:340px">no records</p>';
 }
} 



  while($row = $result->fetch_assoc())
 {
    //$_SESSION["snum"]=$row['sno'];
    //$_SESSION["nam"]=$row['Name'];
    //$_SESSION["quali"]=$row['Qualification'];
   // $_SESSION["emai"]=$row['EmailAddress'];

  echo '<br>';
  echo '<form name="friend" action="a.php" method="post">';
  echo '<input style="margin-left:340px;padding-bottom:10px" type="checkbox" name="friend[]">&nbsp;user Details</input>';
  echo '<br>';
  echo '<br>';
  echo '<div class="container" style="border-style:solid; border-width:medium;width: 550px;">';
  echo '<br>';
    echo 'Name: '.$row['Name']; 
    echo '<br /> EmailAddress: ' .$row['EmailAddress'];
    echo '<br /> Qualification: '.$row['Qualification'];
    echo '<br /> DOB: '.$row['DOB'];
    echo '<br/>';
    echo '<br/>';

    echo '<br/>';
    echo '<br/>';

    echo '</div>';
     echo '<br/>';
  }
  echo '<button type ="submit">invite</button>';
      echo '</form>';
$conn->close();    
?>
Arun Kumaresh
  • 6,211
  • 6
  • 32
  • 50
  • 1
    Possible duplicate of [Display array values in PHP](http://stackoverflow.com/questions/5672796/display-array-values-in-php) – Trevor Dec 28 '15 at 06:47

2 Answers2

1

Try this:

1.The print_r(variable); function is used to print human-readable information about a variable.

2.The var_dump(variable); function is used to display structured information (type and value) about one or more variables.

Manoj S Kadlag
  • 250
  • 2
  • 13
0
    <?php
     $servername = "localhost";
    $username = "root";
    $password = "root";
    $dbname = "myDB";

    // Create connection
    $conn = new mysqli($servername, $username, $password, $dbname);
    // Check connection
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    }

    $count=count($_POST['friend']);
    for($i=0; $i<$count; $i++)
    {
    $a=$_POST['friend'][$i];
    //echo $a;
     $sql = "SELECT Name,EmailAddress,Qualification FROM form WHERE sno='$a'";

    $result=$conn->query($sql);

    while($row = $result->fetch_assoc()){
     $ab=$row['Name'];
    $bc=$row['EmailAddress'];
    $ca=$row['Qualification'];
     echo $ab;
     echo'<br/>';
     echo $bc;
     echo'<br/>';
     echo $ca;
     echo'<br/>';

    $sql1="INSERT INTO arun ". "VALUES('$ab')";
    $result1=$conn->query($sql1);
    }
    }
    if (!$result) {
     //$_SESSION['message10'] = '<p style="color:green;margin-left: 250px";>Your request has been send </p>';

    //header("Location:send.php");
        echo "not send";
    }
     else {
    //   $_SESSION['message11'] = '<p style="color:red;margin-left: 250px";>you have already send request to the user</p>';

    //header("Location:new.php");
        echo "send";
        }
    $conn->close();
?>
Arun Kumaresh
  • 6,211
  • 6
  • 32
  • 50
Nick
  • 9,735
  • 7
  • 59
  • 89
  • 1
    Array ( [0] => on [1] => on [2] => on ) this is what printing when i use print_r($_POST['friend']); or var_dump($_POST['friend']) but i want to display the search result of Name,EmailAddress,Qualifiaction – Arun Kumaresh Dec 28 '15 at 06:44
  • 1
    Than you need put in form also something about this: ``'. And check query `SELECT * FROM form WHERE id in ( :id1, :id2, ...)` to search rows for each id, where `$_POST['friend'][i]` is on. – Nick Dec 28 '15 at 06:54
  • i have got the id but then how can the display the values – Arun Kumaresh Dec 28 '15 at 07:36