we are making an collage project that is about to store website name , category , and details so we are done with website and now we want to make app that will communicate with server through API
. we had simple code like this in php script when data is added into database echo json_encode(true)
. as android programmers know , retrofit library use key value pair type mechanism so we updated code with following.
<?php
$websiteName = $_POST['website_name'];
$websiteCategory = $_POST['website_cat'];
$websiteDetails = $_POST['website_details'];
try {
$pdo = new PDO('mysql:host=localhost;dbname=website' , 'root' , '');
$sql = 'INSERT INTO website_data SET website_name = :website_name , website_cat = :website_cat , website_details = :web_del';
$stmt = $pdo->prepare($sql);
$stmt->bindValue(':website_name' ,$websiteName);
$stmt->bindValue(':website_cat' ,$websiteCategory);
$stmt->bindValue(':web_del' ,$websiteDetails);
$stmt->execute();
echo json_encode(['response' => 'true']);
} catch (PDOException $e) {
$msg = $e->getMessage();
echo json_encode(['response' => $msg]);
}
?>
and here is javascript code that performs operation with ajax
function sendData(websiteName , categoryName , websiteDetails){
var params = 'website_name='+websiteName+'&website_cat='+categoryName+'&website_details='+websiteDetails;
var xml = new XMLHttpRequest();
xml.onreadystatechange = function(){
if(this.status == 200 && this.readyState == 4){
var response = this.responseText;
var responseJson = JSON.parse(response);
console.log('resonse from server' , responseJson['response']);
if(responseJson['response'] == 'true'){
addToCurrent(websiteName , categoryName , websiteDetails);
}else{
alert('unfortunatley data could not added succesfully');
}
} else{
console.log('there is some problem with sever');
}
}
xml.open('POST' , '../php/addNewWebsite.php' , true);
xml.setRequestHeader('Content-type' , 'application/x-www-form-urlencoded');
xml.send(params);
}
this is working as indented in localhost good but it is not working in our free server it shows the alert('unfortunatley data could not added succesfully');
i do not know why does this happening. we have free server and domain from the awardspace.com
UPDATE
here is the error message i am getting from the server SQLSTATE[HY000] [2002] No such file or directory
Thank You .
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…