코드 1 : PHP의 MySQL 데이터베이스 문제
<?php class dbConnect { var $dbHost = 'localhost', $dbUser = 'root', $dbPass = '', $dbName = 'input_oop', $dbTable = 'users'; function __construct() {$dbc = mysql_connect($this->dbHost,$this->dbUser,$this->dbPass) or die ("Cannot connect to MySQL : " . mysql_error()); mysql_select_db($this->dbName) or die ("Database not Found : " . mysql_error()); } } class User extends dbConnect { var $name; function userInput($q) { $sql = "INSERT INTO $this->dbTable set name = '".$q."'"; mysql_query($sql) or die (mysql_error()); } } ?>
이 클래스를 호출하는 코드입니다.
<?php include ('class.php'); $q=$_GET["q"]; $user = new User; $user->userInput($q); ?>
코드 2 :
<?php $q = $_GET['q']; $dbc=mysql_connect("localhost","root","") or die (mysql_error()); mysql_select_db('input_oop') or die (mysql_error()); $sql = "INSERT INTO users set name = '".$q."'"; mysql_query($sql) or die (mysql_error()); ?>
내 코드 내 데이터베이스에 저장 한 :
저장 복수!
내 코드 내 데이터베이스에 저장이 :
내 코드 (1) 어떤 문제가 있습니까?
처음부터 무엇을하고 싶습니까? –
실제 문제 : 데이터베이스에 보내기 전에 모든 들어오는 데이터의 유효성을 확인하십시오. 그렇지 않으면 스크립트가 SQL 인젝션에 취약합니다. 예를 들어'mysql_real_escape()'을 보자. – Ham
Code1에서 userInput() 함수를 어떻게 호출합니까? – harwig