Php_self not working?

+1 TJ Le · August 13, 2014
Hi, I seem to be in a bit of a pickle. Here's the scenario. People register on to my website, and it is now in the mysql database. Now, I want to be able to pull out the information for the database, and display it on the same page. I've followed this code, I could not see anything that would make it falter. Every time I input text and hit the search button, My page would refresh or something, and I would not see or get the information from the database. I tried using php_self, and ? in the form 'action', but it still does not work. I want to be able to search the database for a specific First Name, and pull out the row and all the information that is associated with the 'First Name'. Any ideas? Thanks.

<form name="search" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
Search for: <input type="text" name="find" >
<input type="hidden" name="searching" value="yes" />
<input type="submit" name="search" value="Search" />
//This is only displayed if they have submitted the form
if ($searching =="yes"){
echo "<h2>Results</h2><p>";
//connect to our Database
mysqli_connect("localhost", "TJ", "thinh123") or die(mysqli_error());
mysqli_select_db("TJDB") or die(mysqli_error());
// We preform a bit of filtering
$find = $_POST['find'];
$find = strtoupper($find);
$find = strip_tags($find);
$find = trim ($find);
//Now we search for our search term, in the field the user specified
$data = mysqli_query("SELECT * FROM temp WHERE FirstName LIKE '%$find%'");
//And we display the results
while($result = mysqli_fetch_array($data)){
echo $result['ID'];
echo "<br>";
echo $result['Title'];
echo "<br>";
echo $result['FirstName'];
echo "<br>";
echo $result['LastName'];
//This counts the number or results - and if there wasn't any it gives them a little m$
if ($anymatches == 0){
echo "Sorry, but we can not find an entry to match your query<br><br>";
//And we remind them what they searched for
echo "<b>Searched For:</b> " .$find;

Post a Reply


Oldest  Newest  Rating
0 JOhaL jaTT · August 16, 2014
don't use  echo, just        action="<?php $_SERVER['PHP_SELF'];?>"
0 Jasmin Bakalović · August 16, 2014
I made something, you can try this:

Few days ago i watched mysqli video on phpacademy (inserting data). Currently I'm learning OOP so code might be the same.
  • 1



Server-side, HTML embedded scripting language used to create dynamic Web pages.