-1

I am been trying to connect my android application with my 000Webhost account's MySql Database using PHP.

My Webhost server details are: saravananoct14.web44.net username: xxxx HomeRoot: /home/xxxx ServerName: server10.000webhost.com IPAdress: "ipaddress" MySQL database name:xxxx_sara MySQL user name:xxxx_sarav password for mysql:xxxx!4

my table name is ms. column names:EMAIL_ID,Q1,Q2,Q3.

I have saved my .php files under public_html folder in phpmnMyAdmin.

config.php file is:

<?php

define ('DB_USER',"xxxx_sarav");
define('DB_PASSWORD',"xxxxx!4");
define('DB_DATABASE',"xxxx_sara");
define('DB_SERVER',"mysql1.000webhost.com");
?>

add.php file:

<?php 
$res=array();
if(isset($_POST['EMAIL_ID']) && isset($_POST['Q1']) && isset($_POST['Q2']) &&        isset($_POST['Q3'])){
$EMAIL_ID=$_POST['EMAIL_ID'];
$Q1=$_POST['Q1'];
$Q2=$_POST['Q2'];
$Q3=$_POST['Q3'];

require_once __DIR__.'connect.php';
$db=new DB_CONNECT();
$result=mysql_query("INSERT into ms (EMAIL_ID,Q1,Q2,Q3) values  ('$EMAIL_ID','$Q1','$Q2','$Q3')");
if($result){
$res["success"]=1;
$res["message"]="success";
echo json_encode($res);
}else{
}
}
else
{
$res["success"]=0;
$res["message"]="Required field(s) missing";
echo json_encode($res);
}
?>

I have used the same android program to connect it with my local wamp server and it worked. I have given the following string as Url to parsed using JSON parser is: http://"ip address"/add.php .

I am getting errors as Error Parsing the data. Cannot be converted into !Doctype...

I am pretty sure that I must make a change in the url. But could not find what changes I need to implement so that I can connect with the database. Help me pls....

Dorathy
  • 3
  • 2
  • 7
  • can you open the php from your webbrowser? – A.S. Jan 27 '14 at 11:57
  • Ya..I can open the php file from web browser. – Dorathy Jan 27 '14 at 12:02
  • try to change for debug purposes you php to $_GET the variables and give it in the url and check if there is a error – A.S. Jan 27 '14 at 12:40
  • I tried and this is the error:Caused by: java.lang.IllegalArgumentException: Illegal character in path at index 28: http://"ipAddress"/add.php ?EMAIL_ID=sara%40gmail.com&Q1=Good&Q2=Bad&Q3=Internet – Dorathy Jan 27 '14 at 13:00
  • nono try this url from your browser now and try to get the body of the httprequest and log it – A.S. Jan 27 '14 at 13:20
  • I am sorry.. But I cant understand what you about Explain... And I am sure that I must make changes in URL part.. But I could not figure out what changes I should do.. – Dorathy Jan 27 '14 at 13:26
  • ok to be clear. take your URL and open chrome on your pc and try to open it. – A.S. Jan 27 '14 at 13:27
  • What is `DB_CONNECT()`?.Is it in `__DIR__.'connect.php'? – david strachan Jan 27 '14 at 13:33
  • this is the log i am getting: http://error404.000web host.com/? – Dorathy Jan 27 '14 at 13:33
  • please do me a favor and post your complete URL – A.S. Jan 27 '14 at 13:34
  • So i have it, you should call this URL http://saravananoct14.web44.net/add.php?EMAIL_ID=sara%40gmail.com&Q1=Good&Q2=Bad&Q3=Internet But as you can see you do not have a connect.php – A.S. Jan 27 '14 at 13:36
  • Oh i see you do have a connect.php but with a failure Warning: Unexpected character in input: ''' (ASCII=39) state=1 in /home/a8130812/public_html/connect.php on line 10 – A.S. Jan 27 '14 at 13:36
  • this is my complete url:http://31.170.160.74/add.php – Dorathy Jan 27 '14 at 13:36
  • Parse error: syntax error, unexpected '/' in /home/a8130812/public_html/connect.php on line 10 – A.S. Jan 27 '14 at 13:36
  • ya.. DB_CONNECT() is a class. And it is present in connect.php...@davidstrachan – Dorathy Jan 27 '14 at 13:37
  • NO YOUR URL IS WRONG: THIS IS YOUR URL: http://saravananoct14.web44.net/add.php?EMAIL_ID=sara%40gmail.com&Q1=Good&Q2=Bad&Q3=Internet U are yousing the IP of your hoster, which leads you to his main page – A.S. Jan 27 '14 at 13:37
  • All your files should be in `public_html/` or in directories off it. – david strachan Jan 27 '14 at 13:42
  • I have corrected the error in the connect.php file.. But still I could not write into my databae... – Dorathy Jan 27 '14 at 13:52
  • have you tried it by calling this URL from your firefox/chrome(internet explorer on your PC? I am still getting errors. http://saravananoct14.web44.net/add.php?EMAIL_ID=sara%40gmail.com&Q1=Good&Q2=Bad&Q3=Internet – A.S. Jan 27 '14 at 13:53
  • and please write require_once('connect.php'); – A.S. Jan 27 '14 at 13:53
  • ya.. I tried.. I was able to see ma php files.. – Dorathy Jan 27 '14 at 13:54
  • rly? if I call http://saravananoct14.web44.net/add.php?EMAIL_ID=sara%40gmail.com&Q1=Good&Q2=Bad&Q3=Internet I get error reports – A.S. Jan 27 '14 at 13:55
  • Warning: require_once(__DIR__/connect.php) [function.require-once]: failed to open stream: No such file or directory in /home/a8130812/public_html/add.php on line 10 Free Web Hosting PHP Error Message Fatal error: require_once() [function.require]: Failed opening required '__DIR__/connect.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/a8130812/public_html/add.php on line 10 – A.S. Jan 27 '14 at 13:56
  • try now... i have changed it !!! – Dorathy Jan 27 '14 at 13:58
  • congrats ;) but please do me a favor and validate your input, your api is very volnurable for sqli – A.S. Jan 27 '14 at 14:00
  • I am really sorry.. I am not able to get you... – Dorathy Jan 27 '14 at 14:09
  • A thanks would be good. But have a look at this thread: http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php – A.S. Jan 27 '14 at 14:11

1 Answers1

1

So after we discussed your Problem a long way I will write an Answer:

  1. Please do not call your webservice via IP, always take the URL (especially when you have a webhoster)
  2. Always check your PHP Script via a Browser on your PC, you will see the errors directly.
  3. Debug the errors shown by your php script
Adrian Cid Almaguer
  • 7,815
  • 13
  • 41
  • 63
A.S.
  • 4,574
  • 3
  • 26
  • 43
  • I tried it.. I could not find any error in add.php file.. Still am getting the error as:Error of value
    – Dorathy Jan 28 '14 at 05:56