What's new
  • Welcome to PHCorner Forums. Take a moment to Sign up and gain unlimited access and extra privileges that guests are not entitled to, such as: All that and more! Registration is quick, simple and absolutely free. Join our community today!

Help how to add search in PHP guys

PHC _ Mark

Eternal Poster
Established
Joined
Sep 11, 2016
Messages
1,428
help me po sana sa mga masters dyan :(
thanks in advance guys.
 

Imkaiser101

Enthusiast
Established
Joined
Sep 24, 2018
Messages
163
$search = "";
if(isset($_GET['submit'])){
$search = $_GET['search'];
}
 

Imkaiser101

Enthusiast
Established
Joined
Sep 24, 2018
Messages
163
<?php
include 'connection.php';
$search = "";
if(isset($_GET['submit'])){
$search = $_GET['search'];
}

?>
<!DOCTYPE html>
<html>
<head>
<title>View Contacts</title>
</head>
<body>
<div align="center">
<div style="display: inline-block;">Click Here to<a href="index.php"> add </a>Contacts</div>
<div style="display: inline-block;">
<form method="GET" action="">
<input type="text" name="search" placeholder="SEARCH HERE">
<input type="submit" name="submit" value="submit" >
</form>

</div>
<div>
<table border="1">
<tr>
<th>ID</th>
<th>NAME</th>
<th>PHONE NUM</th>
<th>EMAIL</th>
<th colspan="2">ACTION</th>
</tr>
<?php

$getresultsql = mysqli_query($connect,"SELECT * FROM contacts WHERE (name LIKE '%$search%' OR id = '$search')");
while($getresult = mysqli_fetch_array($getresultsql)){
$id = $getresult[0];
$name = $getresult[1];
$phone = $getresult[2];
$email = $getresult[3];

?>
<tr>
<td><?php echo $id; ?></td>
<td><?php echo $name; ?></td>
<td><?php echo $phone; ?></td>
<td><?php echo $email; ?></td>
<td><a href="<?php echo "update.php?getid=".$id; ?>"><button>View</button></a></td>
<td><a href="<?php echo "delete.php?getid=".$id; ?>"><button>Delete</button></a></td>
</tr>

<?php
}

?>
</table>
</div>
</div>
</body>
</html>


Yan buong php para alam mo
 

Imkaiser101

Enthusiast
Established
Joined
Sep 24, 2018
Messages
163
Isa yan sa mga codes ko ikaw na bahala magpagana sa code mo pag ilalagay muna sayo
 

nogats07

Enthusiast
Established
Joined
Sep 6, 2018
Messages
106
<?php
include 'connection.php';
$search = "";
if(isset($_GET['submit'])){
$search = $_GET['search'];
}

?>
<!DOCTYPE html>
<html>
<head>
<title>View Contacts</title>
</head>
<body>
<div align="center">
<div style="display: inline-block;">Click Here to<a href="index.php"> add </a>Contacts</div>
<div style="display: inline-block;">
<form method="GET" action="">
<input type="text" name="search" placeholder="SEARCH HERE">
<input type="submit" name="submit" value="submit" >
</form>

</div>
<div>
<table border="1">
<tr>
<th>ID</th>
<th>NAME</th>
<th>PHONE NUM</th>
<th>EMAIL</th>
<th colspan="2">ACTION</th>
</tr>
<?php

$getresultsql = mysqli_query($connect,"SELECT * FROM contacts WHERE (name LIKE '%$search%' OR id = '$search')");
while($getresult = mysqli_fetch_array($getresultsql)){
$id = $getresult[0];
$name = $getresult[1];
$phone = $getresult[2];
$email = $getresult[3];

?>
<tr>
<td><?php echo $id; ?></td>
<td><?php echo $name; ?></td>
<td><?php echo $phone; ?></td>
<td><?php echo $email; ?></td>
<td><a href="<?php echo "update.php?getid=".$id; ?>"><button>View</button></a></td>
<td><a href="<?php echo "delete.php?getid=".$id; ?>"><button>Delete</button></a></td>
</tr>

<?php
}

?>
</table>
</div>
</div>
</body>
</html>


Yan buong php para alam mo
Hindi mo na kailangan i-declare yung variable $search bago gamitin. Delikado yung queries mo, risk sa sql injection.
 

Z430

Honorary Poster
Established
Joined
Aug 10, 2015
Messages
715
Easiest way is gamit ka ajax/javascript. :)
 
Thread starter Similar threads Date
P
W
P
I
A

Similar threads


Popular On This Forum

New Topics On This Forum

Forum statistics

Threads
568,897
Messages
11,086,873
Members
1,063,876
Latest member
Cheska Tagala
Top