Title: Run server side php script
Last modified: September 1, 2016

---

# Run server side php script

 *  Resolved [muff1nman](https://wordpress.org/support/users/muff1nman/)
 * (@muff1nman)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/run-server-side-php-script/)
 * Hi Everyone,
 * I am having a little trouble getting a server side php script to run on my Bluehost
   server. This php script is supposed to access a database and pass the data on
   to the client to display certain content on the home page. I am new to web development
   so if you can, please bear with me.
 * The feature I am trying to implement will be some sort of view containing pictures
   of the different apartments that are currently available (the website I am making
   is for a company that manages some apartments). These pictures will have labels
   containing information about where the apartment is and the rent. The picture
   itself will contain a link that when clicked will bring them to a page with more
   detail about the apartment listed as currently available.
 * So to create such a feature I have made a mysql database that is managed by a
   java application on the website owner’s laptop. I have also written a javascript
   file that is intended to request the server to run a php script which then returns
   a string with all of the data in the database (its a database with just one small
   table and no kind of sensitive information that needs to be kept private).
 * The problem is when the javascript I wrote makes the request to the server. I
   have tried all sorts of different kinds of paths (thinking that the issue might
   be that I can only access certain folders on the server) to the php script I 
   want to run but they all result in a Not Found error.
 * I have done some research online but I haven’t found much about how I am supposed
   to make a request to a server running a WordPress site to run a php script. One
   cause of this issue might be that I am new to web development so my understanding
   of how some of this works is incorrect. Another cause might be that I need edit
   some more of the WordPress initialization files.
 * Here is my code thus far.
 * The javascript running on the webpage is used to run the php script I put on 
   the server:
 *     ```
       function getShowing(){
   
           var getting = $.post("http://www.gaylordapartments.net/public_html/WebApp/script.php", {
   
               placeholder: "astring"
   
               }, function(data){ alert(data); })
   
           .fail(function(jqXHR, textStatus, errorThrown){
   
               alert(textStatus.concat(": ").concat(errorThrown).concat("-new error?"));
   
           });
   
       }
   
       $(document).ready(function(){
   
           getShowing();
   
       });
       ```
   
 * Here is the server side php script to get the data I need in the database:
 *     ```
       <?php
   
       getPageData();
   
       function connectToDB(){
   
           $mysqliLink = new mysqli("localhost", "***********", "***************");
   
       	mysql_select_db ("gaylorda_Database1");
   
           if(mysqli_connect_errno()){
   
               echo "not connected";
   
               exit();
   
           } else {
   
               echo "connected";
   
           }
   
       }
   
       function getPageData(){
   
           $mysqliLink = connectToDB();
   
           $query = $mysqliLink->query("select * from Apartments");
   
           $aptno = "";
   
           $building = "";
   
           $showing = 0;
   
           $returnstring = "";
   
           while($row = $query->fetch_object()){
   
               $aptno = $row->aptno;
   
               $building = $row->building;
   
               $showing = $row->showapt;
   
               $returnstring .= $aptno . " " . $building . " " . $showing . ":";
   
           }
   
           echo "<p>" . $returnstring . "</p>";
   
       }
   
       ?>
       ```
   
 * I have checked it over myself and I don’t see any issues but since I am new to
   web development I feel that this is the best place to start looking. I have omitted
   the password and username to the account I use to access the database but I can
   assure you that the one I use is correct. I have verified this through an independent
   program that works fine through another account to access the same database.
 * What are everyone’s thoughts? Is there something wrong in my code? Should I use
   some special path to my php file? Do I have to do something in the WordPress 
   files to get this to function?

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [Garth Mortensen](https://wordpress.org/support/users/voldemortensen/)
 * (@voldemortensen)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/run-server-side-php-script/#post-7522013)
 * Replace
    `var getting = $.post("http://www.gaylordapartments.net/public_html/
   WebApp/script.php", {` with `var getting = $.post("http://www.gaylordapartments.
   net/WebApp/script.php", {`
 *  Thread Starter [muff1nman](https://wordpress.org/support/users/muff1nman/)
 * (@muff1nman)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/run-server-side-php-script/#post-7522055)
 * Thanks voldemortensen, what you suggested worked!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Run server side php script’ is closed to new replies.

## Tags

 * [javascript](https://wordpress.org/support/topic-tag/javascript/)
 * [MySQL](https://wordpress.org/support/topic-tag/mysql/)
 * [not-found-error](https://wordpress.org/support/topic-tag/not-found-error/)
 * [php](https://wordpress.org/support/topic-tag/php/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [muff1nman](https://wordpress.org/support/users/muff1nman/)
 * Last activity: [9 years, 10 months ago](https://wordpress.org/support/topic/run-server-side-php-script/#post-7522055)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
