내 코드는 다음과 같습니다.
mysql_connect('localhost', 'root', 'password');
mysql_select_db('db');
mysql_query("INSERT INTO metabase(url, title, image, description) VALUES('http://www.imgur.com/', '$title', '$image', '$descr')") or die();
오류가 표시되지 않지만 값이 데이터베이스에 삽입되지 않습니다. 내 테이블 이름은 메타베이스입니다. URL, 제목, 이미지는 varchar (255) 및 설명 텍스트입니다. 이것은 오류입니다
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's visual storytelling community. Explore, share, and discuss the best visual sto' at line 1
이것은 설명입니다
The Internet's visual storytelling community. Explore, share, and discuss the best visual stories the Internet has to offer.
그래서 '
어떻게 수정해야하나요?
감가 상각 되기 때문에 PDO 또는 MYSQLi를 사용하는 것이 좋습니다 MySQL_
. 뿐만 아니라 가치를 벗어나지 않고 MySQL 주입과 같은 일부 문제에 노출됩니다.
$pdo = new PDO("mysql:host=localhost;dbname=db","root","password");
$query = $pdo->prepare("INSERT INTO `metabase` (url, title, image, description) VALUES(:url, :title, :image, :descr)");
$query->bindValue(":url", "http://www.imgur.com", PDO::PARAM_STR);
$query->bindValue(":title", $title, PDO::PARAM_STR);
$query->bindValue(":image", $image, PDO::PARAM_STR);
$query->bindValue(":descr", $descr, PDO::PARAM_STR);
$query->execute();
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다