0

The below returns "\nQuery was empty" as I run it simply from my server with the URL in the Browser.

This is the PHP code:

    <?

$databasehost = "server";
$databasename = "xxxx";
$databaseusername ="xxxx";
$databasepassword = "xxxx";
$query = "SELECT * FROM  `Tailor`LIMIT 0 , 30";
$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);
}
?>

3 Answers 3

1

No need to use file_get_content and you have to put one white space after table name.

<?php

$databasehost = "server";
$databasename = "xxxx";
$databaseusername ="xxxx";
$databasepassword = "xxxx";
$query = "SELECT * FROM  `Tailor` LIMIT 0 , 30";
$con = mysql_connect($databasehost,$databaseusername,$databasepassword) or die(mysql_error());
 mysql_select_db($databasename) or die(mysql_error());

$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);
}
?>
Sign up to request clarification or add additional context in comments.

Comments

0

Your query has a problem you need whitespace after tablename

SELECT * FROM  `Tailor` LIMIT 0 , 30

4 Comments

cured it BUT still the same
WHy are you sing this $query = file_get_contents("php://input");?
i removed it was not needed nw im watching out for result
Okay let me know the outcome
0

first

$query = "SELECT * FROM  `Tailor`LIMIT 0 , 30";

but you overwrite it

$query = file_get_contents("php://input"); 

// $query like   aaa=ggg&bbb=kkk

then you

$sth = mysql_query($query);

// LIKE $sth = mysql_query('aaa=bbb&ccc=lll'); //it not sql query format

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.