Jump to content


Photo
- - - - -

Custom PHP search code


  • Please log in to reply
13 replies to this topic

#1 healthcareledger

healthcareledger

    Newbie

  • Members
  • 6 posts

Posted 02 March 2012 - 01:27 AM

I am trying to enter some custom search php code on a page and post the results of the search on the same page. How can I go about doing so? I have the code and have added it the contentbox. It keeps going to an index.php page.

#2 mackenzie

mackenzie

    Advocate

  • Members
  • 333 posts
  • Country: Country Flag

Posted 02 March 2012 - 01:32 AM

Please post your site's url and the PHP code you are trying to implement so we can troubleshoot.

#3 healthcareledger

healthcareledger

    Newbie

  • Members
  • 6 posts

Posted 02 March 2012 - 03:54 PM

Please Login or Register to see this Hidden Content

Code

Search

Search for: in First Name
Results"; //If they did not enter a search term we give them an error if ($find == "") { echo "You forgot to enter a search "dbaddress","dbname ","password") or die('Could not connect to MySQL: ' .mysql_error()); mysql_select_db ("hea1201310200352") or die('Could not connect to MySQL: ' .mysql_error()); $find = strtoupper($find); $find = strip_tags($find); $find = trim($find); $data = mysql_query("SELECT * FROM wp_physicians WHERE upper(fName) like"% $find%""); while ($result = mysql_fetch_array($data)) { echo " "; echo $result['fName']; echo " "; echo $result['LName']; echo " "; echo " "; } $anymatches=mysql_num_rows($data); if ($anymatches == 0) { echo "Sorry, but we can not find an entry to match your query "; } //And we remind them what they searched for echo "Searched For: " .$find; } ?>

#4 catrina

catrina

    Advocate

  • Members
  • 12345 posts
  • LocationCalifornia
  • Country: Country Flag

Posted 02 March 2012 - 04:41 PM

When I search for something, I get this error:

Please Login or Register to see this Hidden Content


There is some kind of error occurring in one of the files for Exec PHP plugin you're using to input your PHP. What happens if you placed the code for the search results on a different page?

#5 healthcareledger

healthcareledger

    Newbie

  • Members
  • 6 posts

Posted 02 March 2012 - 05:33 PM

The same error shows up. Let me ask you this and this might help resolve the issue. I uploaded the exec-php plugin to include custom php code in the html tab. Since I am unable to use the code in the html tab of the page and view the result, I used the code in the contentbox of the mete settings of the page. Is there a way to view the code that was originally pasted in the html tab of the page?

#6 catrina

catrina

    Advocate

  • Members
  • 12345 posts
  • LocationCalifornia
  • Country: Country Flag

Posted 02 March 2012 - 05:41 PM

Is there a way to view the code that was originally pasted in the html tab of the page?


What do you mean by "originally pasted in the HTML tab"? Did you paste the code there in a page before?

#7 Simon_P

Simon_P

    Messer

  • Administrators
  • 8388607 posts
  • LocationDevon
  • Framework Version:2.0
  • Country: Country Flag

Posted 02 March 2012 - 05:45 PM

I dont know what your trying to achieve with that code, but its possibly THE most insecure code I've ever seen.

#8 healthcareledger

healthcareledger

    Newbie

  • Members
  • 6 posts

Posted 02 March 2012 - 05:53 PM

Simon, Being a newbie to coding I appreciate your encouragement. Thank you.

#9 catrina

catrina

    Advocate

  • Members
  • 12345 posts
  • LocationCalifornia
  • Country: Country Flag

Posted 02 March 2012 - 06:00 PM

Are you going to continue using the code?

#10 Simon_P

Simon_P

    Messer

  • Administrators
  • 8388607 posts
  • LocationDevon
  • Framework Version:2.0
  • Country: Country Flag

Posted 02 March 2012 - 06:04 PM

Well what exactly are you trying to search for? Posts? Pages? The wordpress search can be modified using filters.

#11 healthcareledger

healthcareledger

    Newbie

  • Members
  • 6 posts

Posted 02 March 2012 - 06:10 PM

This is what I am trying to do: 1. create some custom code to search against a table in the database 2. Display the search results either on the same page or a new page Is there a tutorial on how to include custom code in the pagelines templates?

#12 Simon_P

Simon_P

    Messer

  • Administrators
  • 8388607 posts
  • LocationDevon
  • Framework Version:2.0
  • Country: Country Flag

Posted 02 March 2012 - 06:14 PM

Well you could create a custom section, and include your code there, but strongly suggest you have a look at the wordpress codex on correct use of the $wpdb class, which will sanitize any queries going to the database.

#13 healthcareledger

healthcareledger

    Newbie

  • Members
  • 6 posts

Posted 02 March 2012 - 06:18 PM

I will. As mentioned to you I am a newbie. Is there a tutorial or document around creating custom sections?

#14 Simon_P

Simon_P

    Messer

  • Administrators
  • 8388607 posts
  • LocationDevon
  • Framework Version:2.0
  • Country: Country Flag

Posted 02 March 2012 - 06:23 PM

Here is a blank section.

Please Login or Register to see this Hidden Content