I have a problem in searching a string which consist of space(manish pandey). php script used to search for only (manish) instead of full name (manish pandey).
I am using here get functions:
image, image2
<!doctype html>
<html lang="en-US">
<head>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset="UTF-8">
</head>
<body>
<?php
/*
Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password)
*/
$link = mysqli_connect("localhost", "root", "root123", "sample");
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
// Attempt select query execution
$sql = "SELECT * FROM qcdataa1 Where project_id='".$_GET['pid']."'";
if($result = mysqli_query($link, $sql)){
if(mysqli_num_rows($result) > 0){
echo "<table>";
echo "<tr>";
echo "<th>sno</th>";
echo "<th>project_id</th>";
echo "<th>project_name</th>";
echo "<th>application</th>";
echo "<th>investigator</th>";
echo "<th>created_by</th>";
echo "<th>creation_date</th>";
echo "<th>last_modified</th>";
echo "</tr>";
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>" .$row['sno']. "</td>";
echo "<td>" .$row['project_id'] . "</td>";
echo "<td>" .$row['project_name']. "</td>";
echo "<td>" .$row['application']. "</td>";
echo "<td><a href=fetchi2.php?iid=" .$row['investigator'].">" .$row['investigator']."</a></td>";
echo "<td>" .$row['created_by']. "</td>";
echo "<td>" .$row['creation_date']. "</td>";
echo "<td>" .$row['last_modified']. "</td>";
echo "</tr>";
}
echo "</table>";
// Close result set
mysqli_free_result($result);
} else{
echo "No records matching your query were found.";
}
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
// Close connection
mysqli_close($link);
?>
</body>
</html>
<!doctype html>
<html lang="en-US">
<head>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset="UTF-8">
</head>
<body>
<?php
/*
Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password)
*/
$link = mysqli_connect("localhost", "root", "root123", "sample");
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
// Attempt select query execution
echo $_GET['iid'];
$sql = "SELECT * FROM qcdataa2 Where first_name='".$_GET['iid']."'";
if($result = mysqli_query($link, $sql)){
if(mysqli_num_rows($result) > 0){
echo "<table>";
echo "<tr>";
echo "<th>sno</th>";
echo "<th>first_name</th>";
echo "<th>last_name</th>";
echo "<th>userid</th>";
echo "<th>password</th>";
echo "<th>emailid</th>";
echo "<th>creation_date</th>";
echo "<th>last_modified</th>";
echo "</tr>";
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>" .$row['sno']. "</td>";
echo "<td>" .$row['first_name'] . "</td>";
echo "<td>" .$row['last_name']. "</td>";
echo "<td>" .$row['userid']. "</td>";
echo "<td>" .$row['password']. "</td>";
echo "<td>" .$row['emailid']. "</td>";
echo "<td>" .$row['creation_date']. "</td>";
echo "<td>" .$row['last_modified']. "</td>";
echo "</tr>";
}
echo "</table>";
// Close result set
mysqli_free_result($result);
} else{
echo "No records matching your query were found.";
}
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
// Close connection
mysqli_close($link);
?>
</body>
</html>
</div>
First make your search term safe and then use it in query using LIKE
instead of =
.
$safe = mysqli_real_escape_string($link, $_GET['iid']);
$safe = trim($safe);
Then query could be,
$sql = "SELECT * FROM qcdataa2 Where first_name LIKE '$safe%' ";
Try sending data with urlencode()
and decode it with urldecode()