New Posts  All Forums:Forum Nav:

Help with PHP script

post #1 of 8
Thread Starter 
So I am trying to connect to a SQL database to access some data that I will be passing into an android application. I know very little about PHP however and the script I am using was not written by me. When I try to run the script in my browser I get a 404 website not found error. I don't know if that is because there is something wrong with my code or if there is another problem.

Here is my Code (Click to show)
?php

$databasehost = "xxxx";
$databasename = "xxxxx";
$databaseusername ="xxxxx";
$databasepassword = "xxxx";

$con = mysql_connect($databasehost,$databaseusername,$databasepassword) or die(mysql_error());
mysql_select_db($databasename) or die(mysql_error());
$query = file_get_contents("php://input");
$sth = mysql_query($query);

if (mysql_errno()) {
header("HTTP/1.1 500 Internal Server Error");
echo $query.'\n';
echo mysql_error();
}
else
{
$rows = array();
while($r = mysql_fetch_assoc($sth)) {
$rows[] = $r;
}
print json_encode($rows);
}
?>

I removed the connection information for privacy reasons, but other than that, that is the code I am using.

Thanks.
post #2 of 8
The code looks good, I bet its the credentials that is your problem. Make sure the dba user is still correct along with password. Also make sure the server the database is on is the correct IP you have in there as well as the hostname.

If you are getting a site not found, its probably the wrong IP address.
Edited by UsedPaperclip - 5/1/12 at 4:06pm
post #3 of 8
Thread Starter 
Quote:
Originally Posted by UsedPaperclip View Post

The code looks good, I bet its the credentials that is your problem. Make sure the dba user is still correct along with password. Also make sure the server the database is on is the correct IP you have in there as well as the hostname.
If you are getting a site not found, its probably the wrong IP address.

The IP address is correct and if I use the same credentials to log on to the database using SQL server management studio, I can access the database just fine.
post #4 of 8
Quote:
Originally Posted by muels7 View Post

The IP address is correct and if I use the same credentials to log on to the database using SQL server management studio, I can access the database just fine.

So you're your using Microsoft SQL server correct? That php script is for mysql, which is an open source sql database.

This link should help you correctly modify the values in the script. The code is correct just the values need to be modified.

http://php.net/manual/en/function.mssql-connect.php
http://php.net/manual/en/book.mssql.php

Just make sure to back it up smile.gif

Edit: Oh and are you testing your credentials to connect using windows authentication or are testing it with the MS sql server dba user and password? If you are using windows credentials, you will need to get sql dba info to get that script to work.
Edited by UsedPaperclip - 5/1/12 at 4:21pm
post #5 of 8
Thread Starter 
Quote:
Originally Posted by UsedPaperclip View Post

So you're your using Microsoft SQL server correct? That php script is for mysql, which is an open source sql database.
This link should help you correctly modify the values in the script. The code is correct just the values need to be modified.
http://php.net/manual/en/function.mssql-connect.php
http://php.net/manual/en/book.mssql.php
Just make sure to back it up smile.gif
Edit: Oh and are you testing your credentials to connect using windows authentication or are testing it with the MS sql server dba user and password? If you are using windows credentials, you will need to get sql dba info to get that script to work.

Ok, thanks, but I think that there may be a bigger issue here. I have found some scripts online that I can run to test if PHP is enable on the server, and no matter what is in the script, I get "page cannot be found"
post #6 of 8
If you post your server OS, MS SQL server version, and Server Roles I can help you get that figured out smile.gif
post #7 of 8
Thread Starter 
Quote:
Originally Posted by UsedPaperclip View Post

If you post your server OS, MS SQL server version, and Server Roles I can help you get that figured out smile.gif

I've given up on this, at least for now. I am going to try setting up my own web server with appache, and run MySQL and PHP, on it. That way I will have access to the server settings. I was able to get a free domain name to use with my IP. Hopefully that will work for me.....

All this work to make an android application I'm not even going to publish. This is for a school project.
post #8 of 8
The first character of the script should be '<'. Did you just leave that out of your pasted text or is that actually missing?
     
CPUMotherboardGraphicsRAM
Intel Core i7-4770K Gigabyte G1.Sniper M5 EVGA GTX 780 SC Crucial Ballistix Sport 2 x 8GB 
Hard DriveHard DriveHard DriveOptical Drive
Samsung 840 Pro 256GB Seagate Barracuda 3TB Seagate Barracuda 4TB Asus BD-ROM 
CoolingOSMonitorKeyboard
Noctua NH-D14 Windows 8 Pro Dell U2713HM Ducky YOTD (MX Brown) 
PowerCaseMouseMouse Pad
SeaSonic SS-760XP2 Fractal Design Arc Mini Roccat Savu SteelSeries 9HD 
Audio
Beyerdynamic DT990 250 Ohm 
CPUMotherboardGraphicsRAM
AMD A6-3500 Asrock A75M HD 6530D Samsung 4GB DDR3 1600  
Hard DriveHard DriveHard DriveOptical Drive
Intel 320 80GB Samsung Spinpoint F4 2TB WD Caviar Green 3TB Sony BD-Rom 
CoolingOSMonitorKeyboard
Noctua NH-C12P SE14 Win 7 Professional 64-bit Samsung LN46C600 Lenovo N5902 
PowerCaseOther
Corsair CX430 Antec Veris Fusion HDHomeRun Prime 
CPUMotherboardGraphicsRAM
AMD Phenom II X3 B55 Asus M5A99X EVO Sapphire HD 7950 G.Skill 8GB DDR3 
Hard DriveOptical DriveCoolingMonitor
Samsung F3 1TB LG DVD-RW CM Hyper 212 Plus Dell U2312HM 
KeyboardPowerCaseMouse
Pink KBT Race (MX Blue) Lepa G700-MA Corsair 500R Razer Abyssus 
Mouse Pad
Razer Goliathus Speed 
  hide details  
Reply
     
CPUMotherboardGraphicsRAM
Intel Core i7-4770K Gigabyte G1.Sniper M5 EVGA GTX 780 SC Crucial Ballistix Sport 2 x 8GB 
Hard DriveHard DriveHard DriveOptical Drive
Samsung 840 Pro 256GB Seagate Barracuda 3TB Seagate Barracuda 4TB Asus BD-ROM 
CoolingOSMonitorKeyboard
Noctua NH-D14 Windows 8 Pro Dell U2713HM Ducky YOTD (MX Brown) 
PowerCaseMouseMouse Pad
SeaSonic SS-760XP2 Fractal Design Arc Mini Roccat Savu SteelSeries 9HD 
Audio
Beyerdynamic DT990 250 Ohm 
CPUMotherboardGraphicsRAM
AMD A6-3500 Asrock A75M HD 6530D Samsung 4GB DDR3 1600  
Hard DriveHard DriveHard DriveOptical Drive
Intel 320 80GB Samsung Spinpoint F4 2TB WD Caviar Green 3TB Sony BD-Rom 
CoolingOSMonitorKeyboard
Noctua NH-C12P SE14 Win 7 Professional 64-bit Samsung LN46C600 Lenovo N5902 
PowerCaseOther
Corsair CX430 Antec Veris Fusion HDHomeRun Prime 
CPUMotherboardGraphicsRAM
AMD Phenom II X3 B55 Asus M5A99X EVO Sapphire HD 7950 G.Skill 8GB DDR3 
Hard DriveOptical DriveCoolingMonitor
Samsung F3 1TB LG DVD-RW CM Hyper 212 Plus Dell U2312HM 
KeyboardPowerCaseMouse
Pink KBT Race (MX Blue) Lepa G700-MA Corsair 500R Razer Abyssus 
Mouse Pad
Razer Goliathus Speed 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming