업데이트하지 않는 지금 내가 내 데이터베이스에이를 추가 할 내가 여기SQL 삽입 쿼리 삽입 여러 번 내가의 일부 데이터를 삽입 할
var link = 'somelink';
var stmt = "SELECT * FROM card WHERE Productsync = 0 ";
//console.log(stmt);
$cordovaSQLite.execute(db, stmt).then(function(res) { //console.log(res)
if(res.rows.length > 0) {
for (var i = 0; i < res.rows.length; i++){
console.log(res.rows.item(i));
console.log(res.rows.item(i).ProductName);
console.log(res.rows.item(i).ProductBarcode);
console.log(res.rows.item(i).ProductPakking);
console.log(res.rows.item(i).ProductPresent);
console.log(res.rows.item(i).ProductMinimuim);
console.log(res.rows.item(i).FotoUrl);
console.log(res.rows.item(i).DBid);
$http.post(link, {ProductName : res.rows.item(i).ProductName , ProductBarcode : res.rows.item(i).ProductBarcode , ProductPakking : res.rows.item(i).ProductPakking , ProductPresent : res.rows.item(i).ProductPresent , ProductMinimuim : res.rows.item(i).ProductMinimuim , FotoUrl : res.rows.item(i).FotoUrl , DBid : res.rows.item(i).DBid}).then(function (res){//sending data
console.log(res.data);//respone of server
var data = res.data;
for (var key in data) {//read out respone
if (data.hasOwnProperty(key)) {
var obj = data[key];
console.log(obj);
//have to make this
}
}
});
}
}
});
을이를 보내 자바 스크립트 (코르도바 응용 프로그램)로 보낼 수있다 온라인 난 그냥 (내가 원하는)
productsnames를보고, 내가 PHP에서 쿼리하기 전에 $ 제품명 에코 언제 PHP 스크립트가
$postdata = file_get_contents("php://input");
if (isset($postdata)) {
$request = json_decode($postdata);
$ProductName = $request->ProductName;
$ProductBarcode = $request->ProductBarcode;
$ProductPakking = $request->ProductPakking;
$ProductPresent = $request->ProductPresent;
$ProductMinimuim = $request->ProductMinimuim;
$FotoUrl = $request->FotoUrl;
$DBid = $request->DBid;
$ProductName = mysqli_real_escape_string($connection,$ProductName);
$ProductBarcode = mysqli_real_escape_string($connection,$ProductBarcode);
$ProductPakking = mysqli_real_escape_string($connection,$ProductPakking);
$ProductPresent = mysqli_real_escape_string($connection,$ProductPresent);
$ProductMinimuim = mysqli_real_escape_string($connection,$ProductMinimuim);
$FotoUrl = mysqli_real_escape_string($connection,$FotoUrl);
$DBid = mysqli_real_escape_string($connection,$DBid);
$query ="REPLACE into `card` (ProductName,ProductBarcode,ProductPakking,ProductPresent,ProductMinimuim,FotoUrl,DBid)
VALUES('" . $ProductName . "' ,
'" . $ProductBarcode . "' ,
'" . $ProductPakking . "' ,
'" . $ProductPresent . "' ,
'" . $ProductMinimuim . "' ,
'" . $FotoUrl . "' ,
'" . $DBid ."')";
과 같은 방법이있다 (BIND 변수는 나중에 할 것) 내 probl em은 다음과 같습니다. 이미 존재하는 경우 값을 대체하지 않고 여러 번 삽입합니다. 한 번만 삽입하고 열이 이미있는 경우 바꾸거나 업데이트해야합니다.
누군가가 내 도움을 줄 수 있습니까? PHP에서
업데이트 쿼리는
$query ="SELECT ProductName FROM `card` WHERE
`ProductName` = '" . $ProductName . "' AND
`ProductBarcode` = '" . $ProductBarcode . "' AND
`ProductPakking` = '" . $ProductPakking . "' AND
`ProductPresent` = '" . $ProductPresent . "' AND
`ProductMinimuim` = '" . $ProductMinimuim . "' AND
`FotoUrl` = '" . $FotoUrl . "' AND
`DBid` = '" . $DBid ."'";
$result_set = mysqli_query($connection,$query);
if (mysqli_num_rows($result_set) == 0){
$query ="INSERT INTO `card` (ProductName,ProductBarcode,ProductPakking,ProductPresent,ProductMinimuim,FotoUrl,DBid)
VALUES('" . $ProductName . "' ,
'" . $ProductBarcode . "' ,
'" . $ProductPakking . "' ,
'" . $ProductPresent . "' ,
'" . $ProductMinimuim . "' ,
'" . $FotoUrl . "' ,
'" . $DBid ."')";
$result = mysqli_query($connection,$query);
}else{
$query = "UPDATE `card`
SET `ProductName` = '" . $ProductName . "' ,
`ProductBarcode` = '" . $ProductBarcode . "' ,
`ProductPakking` = '" . $ProductPakking . "' ,
`ProductPresent` = '" . $ProductPresent . "' ,
`ProductMinimuim` = '" . $ProductMinimuim . "' ,
`FotoUrl` = '" . $FotoUrl . "' ,
`DBid` = '" . $DBid ."'
WHERE `ProductBarcode` = '" . $ProductBarcode . "' AND `DBid` = '" . $DBid ."'";
$fines = mysqli_query($connection,$query);
}
맞다면'userID'는'card' 테이블의 프라이 머리 키이고,'userID'를'REPLACE' 쿼리에 넘겨주지 않을 것입니다. – antorqs
죄송합니다, 저의 죄송 합니다만, 아직 온라인 데이터베이스에 관한 내용입니다 ... –