나는 html 형식을 만들었고 사용자가 만든 mysqli 데이터베이스에 양식을 채울 데이터를 보내려고했습니다. 데이터베이스를 만들고 양식에있는 6 개의 필드에 대해 6 개의 열을 만들었습니다. 내가 작업을 수행하려면 다음의 PHP 코드를 작성하지만이 작동하지 않는 것 ...html 형식의 데이터를 mysqli 데이터베이스에 게시
<?php
//get the form elements and store them in variables
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$postal = $_POST['postal'];
$acceptance = $_POST['acceptance'];
//establish connection
$con = mysqli_connect('localhost', 'db_user', 'db_password' , 'db_name', 'db_socket');
//on connection failure, throw an error
if(!$con) {
die('Could not connect: '.mysql_error());
}
$sql = 'INSERT INTO db_table1 (firstname, lastname, email, postal, phone, acceptance)
VALUES ($_POST[firstname], $_POST[lastname], $_POST[email], $_POST[postal], $_POST[phone], $_POST[acceptance])' ;
if ($sql) {
echo 'Success';
}
else {
die ('Error');
}
$mysqli->close();
//Redirects to the specified page
header("Location: http://www.example.com/success");
?>
당신이 나를 도울 수 있을까요? 어디서 문제가 생기고 DB에 아무것도 들어 가지 않습니까?
경고 ** ** mysql을 사용할 때 [매개 변수가있는 쿼리] (http://php.net/manual/en/mysqli.quickstart.prepared-statements.php)와 ['bind_param' ] (http://php.net/manual/en/mysqli-stmt.bind-param.php)를 사용하여 쿼리에 사용자 데이터를 추가하십시오. ** 심각한 [SQL injection bug] (http://bobby-tables.com/)를 만들었 기 때문에 문자열 보간이나 연결을 사용하여 **이를 수행하지 마십시오. **'$ _POST' 또는'$ _GET' 데이터를 쿼리에 직접 입력하지 마십시오. 실수로 누군가를 악용하려고 시도하면 매우 위험 할 수 있습니다. – tadman