Monday, August 5, 2019

PHP form to search data in MySQL db

I try to open this post to receive some help about a problem with a search form that doesn't work correctly.



I have a MySQL DB with some data stored in different tables:



DB is: list_pec
Table are: pec_1, pec_2, pec_3 and pec_4




All of these tables contain the same rows with different data. Rows are
firstame, lastname, email, id_client, id_2client



My goal is to create a search form in PHP in which there are an input label and a selection form that is used to connect to the database and give me as an output query result.



Below PHP file to connect MySQL DB that I called "conn.php"



$host = "localhost";

$userName = "demo";
$password = "demo";
$dbName = "list_pec";

// Create database connection
$conn = new mysqli($host, $userName, $password, $dbName);

// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);

}
?>


below file called "search.php" in which there's form and php code, obv i want have query result in the same .php file so i used in form action



error_reporting(E_ALL);
ini_set('display_errors', '1');
include("conn.php");


$search_output = "";
if (isset($_POST["submit"])){
if($_POST['option']== "a"){
$sqlcommand="SELECT email, id_client, id_2client FROM pec_1 WHERE email = 'email'";
}

else if ($_POST['option'] == "b"){
$sqlcommand="SELECT email, id_client, id_2client FROM pec_2 WHERE email = 'email'";
}


else if ($_POST['option'] == "c"){
$sqlcommand="SELECT email, id_client, id_2client FROM pec_3 WHERE email = 'email'";
}

else if ($_POST['option'] == "d"){
$sqlcommand="SELECT email, id_client, id_2client FROM pec_4 WHERE email = 'email'";
}




$query = mysqli_query($conn,$sqlcommand) or die (mysqli_error($conn));
$search_output .="
query result: ";
if ($row = mysqli_fetch_array($query)){
$email = $row ["email"];
$pec = $row ["id_client"];
$sdi = $row ["id_2client"];
$search_output .= "

$email - $id_client - $id_2client

";



} else{
$search_output= "
No Result";

}
}
?>





Search id_client and id_2client





Search id_client and id_2client































hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...