Question: How do I search in my database? Also how can I fix my code so that the entries show up in the table. I just

How do I search in my database? Also how can I fix my code so that the entries show up in the table. I just started coding today so I am not very knowledgable. Here are the requirements:

I am stuck on 3 and 4 I am using XAMPP I have already made the database table, the name of my database is exam1 and the name of the table is testt1

1) create a database table (see Table 2 & 3) with at least 10 data and must include your own name; (30%)

2) create a PHP enhanced HTML webpage (see Figure 5) that will be able to retrieve all of them; (30%)

3) add a new function (e.g., icon, button, webpages, etc.) to 2) that will allow you to insert new data into the table; (20%)

4) add a new function (e.g., icon, button, webpages, etc.) to 3) that all you to retrieve any data that are searched; (10%) and 5) add any appropriate functions to 4) to promote your webpage. (10%

here is my code so far:

CODE FOR INDEX

$con=mysqli_connect("localhost","root","Midweek42!","exam1"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $sql="SELECT ID,FirstName,lastName,Number,email FROM testt1"; ?>

Users on Database

Users in Database

ID First Name Last Name Telephoe Email

Search:

if ($result=mysqli_query($con,$sql)) { while ($row=mysqli_fetch_array($result)) { echo ""; echo "" . $row['ID'] . ""; echo "" . $row['FirstName'] . ""; echo "" . $row['lastName'] . ""; echo "" . $row['Number'] . ""; echo "" . $row['email'] . ""; echo ""; } // Free result set mysqli_free_result($result); }

mysqli_close($con); ?>

$servername = "localhost"; $username = "root"; $password = "Midweek42!"; $dbname = "exam1";

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

$ $sql = "INSERT INTO testt1 (ID, FirstName, lastName, Number, email) VALUES ('', ' ', ' ')"; if ($conn->query($sql) === TRUE) { echo "New record created successfully"; } else { echo "Error: " . $sql . " " . $conn->error; }

$conn->close(); ?>

CODE FOR SEARCH_DATABASE.PHP

//load database connection

$host = "localhost";

$user = "root";

$password = "Midweek42!";

$database_name = "exam1";

$pdo = new PDO("mysql:host=$host;dbname=$database_name", $user, $password, array(

PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION

));

// Search from MySQL database table

$search=$_POST['search'];

$query = $pdo->prepare("select * from testt1 where lastNAme LIKE '%$search%' OR ID LIKE '%$search%' OR email LIKE '%$search%' LIMIT 0 , 10");

$query->bindValue(1, "%$search%", PDO::PARAM_STR);

$query->execute();

// Display search result

if (!$query->rowCount() == 0) {

echo "Search found :
";

echo "

";

echo "

";

while ($results = $query->fetch()) {

echo "

";

}

echo "

lastName ID email
";

echo $results['lastName'];

echo "

";

echo $results['ID'];

echo "

";

echo "$".$results['email'];

echo "

";

} else {

echo 'Nothing found';

}

?>

please edit it so that the data in my database shows up in the table, and that my search bar works! Thank you!!

How do I search in my database? Also how can I fix

Users on Database Users in Database ID First Name | Last NameTelephoe Email Submit 01BrittanyHines7572925941bmhines46@gmail.com7890123Dnita Graham6764440939dnita@yahoo.com987634Eve Search: Hines Adams8482004877eve@gmail.com89938S3JaneDoe7574440292jdoe@gmail.com4444432JanetJacky7573388119johnnyboy@example.com2222222JockSchool8884440009schooljock@email.com1010101JohnI Smith7573320000nettaSmith@gmail.com Error: SELECT ID.FirstName,lastName,Number,email FROM testtl

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!