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?
The topic ‘Run server side php script’ is closed to new replies.