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

Forum Veteran
Established
Joined
Sep 11, 2016
Messages
2,431
Reaction score
557
help me po sana sa mga masters dyan :(
thanks in advance guys.
 

Imkaiser101

Enthusiast
Established
<?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
 

Fitzflor17

Grasshopper
Established
tnks sa mga nag turo
 

nogats07

Enthusiast
Established
<?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.
 

Trending Topics

Trending On This Forum

New Topics On This Forum

Top