원래 게시물 :배열에서 변수를 추출한 mysql_real_escape_string
내 스크립트가 작동하지 않습니다 (데이터를 기록하지 않습니다). 나는 mysql_real_escape_string를 추가하기 전에 작동, 그래서 어쩌면 내가 제대로 구현하지 않은 경우 궁금하네요 :
$array = json_decode($downstream,TRUE);
$name = $array["status"]["name"];
$title = $array["status"]["title"];
$table = "mrTable";
$insert = "INSERT INTO $table (name, title) VALUES ('".mysql_real_escape_string($name)."', '".mysql_real_escape_string($title)."')";
이 INSERT에서 그 구현이 당신에게 올바른 보입니까
?UPDATE : 여기
희망이 도움이 될 것입니다, 전체 코드입니다. 그래도 여전히 작동하지 않습니다. real_escape_string 함수가 사용되면 데이터 요소 중 NONE이 데이터베이스에 기록됩니다. 이스케이프 기능을 제거하자마자 아포스트로피가 나타나지 않는 한 데이터는 잘 기록됩니다. 여기
은 우리가 간다 :
//read contents of this file:
$json_data = file_get_contents('../list.txt');
//json to a php array
$array = json_decode($json_data,TRUE));
//store in mysql table
$table = "table1";
$name = mysql_real_escape_string($array["current"]["name"]);
$code = mysql_real_escape_string($array["current"]["code"]);
$insert="INSERT INTO $table (name, code) VALUES ('$name', '$code')";
$con = mysql_connect($db, $user, $pass);
if (!$con)
{
die ('Could not connect: ' . mysql_error());
};
mysql_select_db($yup, $con);
mysql_query($insert) OR die(mysql_error());
mysql_close($con);
업데이트 2
고정! 먼저 mysql_real_escape_string을 언급하기 전에 데이터베이스에 연결해야합니다. 모든 것이 지금 작동 중입니다 ... 빈 데이터가 없습니다.
변수 $ name이 없습니다. 대신 $ artist를 입력해야합니다. –
그리고 실행 후 오류를 확인 했습니까? mysql_error()의 출력? –
Eugene -이 게시물의 코드를 복사하는 동안 내 오류였습니다. 변수 이름은 실제 스크립트에서 일관 적입니다. – Phoebe