Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

extremely simple PHP MySQL data request script not working.

Codes here !

Moderators: macek, egami, gesf

extremely simple PHP MySQL data request script not working.

Postby EchoSeven » Wed May 28, 2014 3:18 am

Hello. i am writing an API for lua... that sends POST requests to a php script. this php script is malfunctioning. below is the code and error.

Code:
Code: Select all
<?php
 
        $host = $_POST['host'];
        $port = $_POST['port'];
        $user = $_POST['user'];
        $password = $_POST['password'];
        $db = $_POST['db'];
        $query = $_POST['query'];
        $query = urldecode($query);
 
        $connection = mysql_connect($host,$user,$password) or die("err1");
        mysql_select_db($db) or die("err2");
 
        $resource = mysql_query($query);
 
        $rows = array();
        while($r = mysql_fetch_object($resource)){
                $rows[] = $r;
        }
 
        echo json_encode($rows);
      //echo $rows;
 
        mysql_close();
 
?>


Error:
Code: Select all
html passed to JSON:decode(): <br /><b>Warning</b>: mysql_fetch_object(): supplied argument is not valid MySQL result resource in [server url] on line 17


Note: it does actually connect to the Database as per previous experiments with the code. JSON:decode() is working and therefore not the problem, since it was the PHP that gave this error to the JSON handler API. The server is working correctly as i use it all the time to make MySQL requests. though, never with this php code. i use a framework to do it for me. but it seems to be working correctly which verifies this php script ás what is malfunctioning.
EchoSeven
New php-forum User
New php-forum User
 
Posts: 1
Joined: Wed May 28, 2014 2:59 am

Return to mySQL & php coding

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.