PHP parsing and MySQL Query Error

I seem to be having trouble with my php code. I have constructed the query using phpMyAdmin where it works without any problems. However, once I insert the sql query into this php code it does not seem to work at all.

[php]

<?php mysql_connect("127.0.0.1", "root", "password"); mysql_select_db("transport"); $q = mysql_query("SELECT * FROM `tube` WHERE `code` = 'B'"); while ($row = mysql_fetch_assoc($q)) $output[] = $row; print(json_encode($output)); mysql_close(); ?>

[/php]

I keep getting the following error message when I try and execute the php script using my web browser. I would just like it known that the mySQL database and the php script are both located on an external server.

HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfil the request.

Any help regarding the coding would be helpful.

Check permission of the file, if you can read with apache user(or user of web service) try to put “die(‘A string to check’)”, after mysql_select_db, or print mysql_error, to check this.

Syntax of “SELECT” are correct, but it’s not necesary put tube or code you can use “SELECT * FROM tube WHERE code = ‘B’”

But error, must be at permission or web service configuration, check .htaccess, config, etc.

I am not sure what to do with the htaccess. But I did add the directory to the file.

With permissions for the script it is set at rw- r-- r-- .

[php]

<?php define('dbname',"dbname"); define('dbusername',"dbusername"); define('dbpass',"pass"); define('dbhost','10.10.10.1'); mysql_connect(dbhost,dbusername,dbpass); echo "Connected to MySQL
"; mysql_select_db(dbname); echo "Connected to Database
"; $q=mysql_query("SELECT * FROM tube WHERE code = B"); while($row=mysql_fetch_assoc($sql)) $output[]=$row; print(json_encode($output)); mysql_close(); ?>

[/php]

I now get the following message when I try to execute the script using my browser:
Connected to MySQL
Connected to Database
null

Any ideas?

Sponsor our Newsletter | Privacy Policy | Terms of Service