ID가 존재하는지 확인하고 싶습니다. id가 존재하지 않으면 SQL 데이터베이스에 행을 삽입해야합니다. 여기 내 코드가있다. 그러나 문제는 항상 행을 삽입한다는 것입니다.동일한 ID가 이미 존재하지 않으면 행 삽입
mysql_select_db($database_include, $include);
$query_user = "SELECT * FROM `user` WHERE `userid` = '$id'";
$user = mysql_query($query_user, $include) or die(mysql_error());
$row_user = mysql_fetch_assoc($user);
$totalRows_user = mysql_num_rows($user);
if($totalRows_user == 0){
mysql_select_db($database_include, $include);
$query_insert = "INSERT INTO user (userid, point, followors)VALUES ($id,'10','0');";
$user = mysql_query($query_insert, $include) or die(mysql_error());
}
무엇을할까요?
[Little Bobby] (http://bobby-tables.com/)는 [귀하의 스크립트는 SQL 주입 공격의 위험이 있습니다.] (http://stackoverflow.com/questions/60174/how-can-i) -prevent-sql-injection-in-php). 심지어 [이스케이프 문자열] (http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string) 안전하지 않습니다! –
[mysql_ *'함수 사용을 중단하십시오] (http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). [이 확장 기능] (http://php.net/manual/en/migration70.removed-exts-sapis.php)은 PHP 7에서 삭제되었습니다. [prepared] (http://en.wikipedia.org/)에 대해 알아보십시오. wiki/Prepared_statement) 문을 [PDO] (http://php.net/manual/en/pdo.prepared-statements.php) 및 [MySQLi] (http://php.net/manual/en/mysqli.quickstart .prepared-statements.php) PDO 사용을 고려해보십시오. [정말 쉽습니다] (http://jayblanchard.net/demystifying_php_pdo.html). –