PHP script help

CJcorp (CJcorp.epizy.com)

Hi I am making an application for android phone which uses infinityfree.net MySql database to store user data i need help in design a php script through which I can post query about Insert, read, delete and update database data from my application can any one help me regarding this I tried with a php script but it’s not working

Here is thee script

<?php

//DATABSE DETAILS//
$DB_ADDRESS="sql306.ultimatefreehost.in";
$DB_USER="ltm_24835408";
$DB_PASS="HIDDEN BY MOD";
$DB_NAME="ltm_24835408_MovieHouseHD";

//SETTINGS//
//This code is something you set in the APP so random people cant use it.
$SQLKEY="MovieHouseHD";

/************************************CONFIG****************************************/

//these are just in case setting headers forcing it to always expire
header('Cache-Control: no-cache, must-revalidate');

error_log(print_r($_POST,TRUE));

if( isset($_POST['query']) && isset($_POST['key']) ){                                   //checks if the tag post is there and if its been a proper form post
  //set content type to CSV (to be set here to be able to access this page also with a browser)
  header('Content-type: text/csv');

  if($_POST['key']==$SQLKEY){                                                           //validates the SQL key
    $query=urldecode($_POST['query']);
    if(get_magic_quotes_gpc()){     //check if the worthless pile of crap magic quotes is enabled and if it is, strip the slashes from the query
      $query=stripslashes($query);
    }
    $conn = new mysqli($DB_ADDRESS,$DB_USER,$DB_PASS,$DB_NAME);    //connect

    if($conn->connect_error){                                                           //checks connection
      header("HTTP/1.0 400 Bad Request");
      echo "ERROR Database Connection Failed: " . $conn->connect_error, E_USER_ERROR;   //reports a DB connection failure
    } else {
      $result=$conn->query($query);                                                     //runs the posted query
      if($result === false){
        header("HTTP/1.0 400 Bad Request");                                             //sends back a bad request error
        echo "Wrong SQL: " . $query . " Error: " . $conn->error, E_USER_ERROR;          //errors if the query is bad and spits the error back to the client
      } else {
        if (strlen(stristr($query,"SELECT"))>0) {                                       //tests if it's a SELECT statement
          $csv = '';                                                                    // bug fix Undefined variable: csv
          while ($fieldinfo = $result->fetch_field()) {
            $csv .= $fieldinfo->name.",";
          }
          $csv = rtrim($csv, ",")."\n";
          echo $csv;                                                                    //prints header row
          $csv = '';

          $result->data_seek(0);
          while($row = $result->fetch_assoc()){
            foreach ($row as $key => $value) {
              $csv .= $value.",";
            }
            $csv = rtrim($csv, ",")."\n";
          }
          echo $csv;                                                                    //prints all data rows
        } else {
          header("HTTP/1.0 201 Rows");
          echo "AFFECTED ROWS: " . $conn->affected_rows;       //if the query is anything but a SELECT, it will return the number of affected rows
        }
      }
      $conn->close();                                          //closes the DB
    }
  } else {
     header("HTTP/1.0 400 Bad Request");
     echo "Bad Request";                                       //reports if the secret key was bad
  }
} else {
        header("HTTP/1.0 400 Bad Request");
        echo "Bad Request";
}
?>

I don’t know much about PHP, but it would;
a, Be easier if it was on it’s individual line rather than everywhere.
b, Please blur your personal information such as your account + password
c, This may help you;

But with adding in recieving the post as so;

Sorry i am giving you some very basic stuff, but it looks like the comments may be messing it up, as the comments are everywhere, try without them

Details I provided is no longer available in any website or any dB and dB details are is just a friction not functional

Ah ok, and try it without the comments and place everything on a new line, it seems that the comments are marking code and code are marking comments

It maybe blocked by the security system unless it is a “WebView”

2 Likes
<?php

$DB_ADDRESS="sql306.ultimatefreehost.in";
$DB_USER="ltm_24835408";
$DB_PASS="HIDDEN BY MOD";
$DB_NAME="ltm_24835408_MovieHouseHD";


$SQLKEY="MovieHouseHD";


header('Cache-Control: no-cache, must-revalidate');

error_log(print_r($_POST,TRUE));

if( isset($_POST['query']) && isset($_POST['key']) ){                                   
  header('Content-type: text/csv');

  if($_POST['key']==$SQLKEY){                                                           
    $query=urldecode($_POST['query']);
    if(get_magic_quotes_gpc()){     
        
      $query=stripslashes($query);
    }
    $conn = new mysqli($DB_ADDRESS,$DB_USER,$DB_PASS,$DB_NAME);    

    if($conn->connect_error){                                                           
      header("HTTP/1.0 400 Bad Request");
      echo "ERROR Database Connection Failed: " . $conn->connect_error, E_USER_ERROR;   
    } else {
      $result=$conn->query($query);                                                 
      
      if($result === false){
        header("HTTP/1.0 400 Bad Request");                                             
        echo "Wrong SQL: " . $query . " Error: " . $conn->error, E_USER_ERROR;          
      } else {
        if (strlen(stristr($query,"SELECT"))>0) {                                       
          $csv = '';                                                                    
          while ($fieldinfo = $result->fetch_field()) {
            $csv .= $fieldinfo->name.",";
          }
          $csv = rtrim($csv, ",")."\n";
          echo $csv;                                                                    
          $csv = '';

          $result->data_seek(0);
          while($row = $result->fetch_assoc()){
            foreach ($row as $key => $value) {
              $csv .= $value.",";
            }
            $csv = rtrim($csv, ",")."\n";
          }
          echo $csv;                                                                    
        } else {
          header("HTTP/1.0 201 Rows");
          echo "AFFECTED ROWS: " . $conn->affected_rows;       
        }
      }
      $conn->close();                                          
    }
  } else {
     header("HTTP/1.0 400 Bad Request");
     echo "Bad Request";                                       
  }
} else {
        header("HTTP/1.0 400 Bad Request");
        echo "Bad Request";
}
?>

Is it possible to use infinity free as dB for mobile application

no, free plans doesn’t have remote sql. Meaning, the sql server is only be used in your website.

3 Likes

Is there any difference between 000webhost hosting and infinity free hosting because they provide the features

Yes, they are run on different systems and ran completely different, and yes it is the fact that MySQL Can only be used on InfinityFree’s web hosting, and not remotely, however the PHP is perfect.

1 Like

Looking at your code, you’re not using InfinityFree.net, but ultimatefreehost.in. Yes, they use the same platform as we do, so much of the same information applies. But remember this is the support forum for InfinityFree, not for it’s competitors. If you are unhappy with the support offered by your current hosting provider and you prefer our support, please consider using our hosting as well so we can help you more effectively.

We may be able to help you with this, but it would help us greatly if we had more information about the issue than “it’s not working”.

3 Likes

Ok icon provide you more details and regarding ultimatefreehost.in I was tryied same thing to do with that but it’s not working so that it’s written there
Nothing more than that

Trying to execute the query
INSERT INTO GSUserData VALUES (‘+91’, ‘700383’, ‘Ait’, ‘chey’, ‘image’)

NOTHING IS happening

!

Now you have all details so please try to solve the problems

Is that what you want to be solved?

You cannot access our databases from other websites or apps. in short you should use other database providers, we offer the database feature for web hosting purpose, not store of other sites/apps.

7 Likes

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.