PHP/MYSQL에서 준비된 문을 배우려고합니다. 여기에 많은 제안이 있기 때문에. 이 오류가 계속 발생합니다.준비된 문을 시도 할 때 매개 변수를 전달할 수 없습니다.
Fatal error: Cannot pass parameter 2 by reference in C:\xampp\htdocs\blog\admin\create.php on line 57
누구든지이 문제를 해결하는 방법을 알려주시겠습니까? 나는 주변을 둘러 보았고 나는 이것을 해결하는 데 도움이 될만한 것을 찾을 수 없다.
<?php
require_once '../config.php';
// Check to see if the title was entered from new.php
if ($_POST['title'])
{
$title = $_POST['title'];
} else {
echo "No title was entered. Please go back. <br />";
}
// Check to see if the body was entered from new.php
if ($_POST['body'])
{
$body = $_POST['body'];
} else {
echo "No body was entered. Please go back. <br />";
}
// Get the date
$date = time();
// ID = NULL because of auto-increment
$id = 'NULL';
// If magic_quotes_gpc returns true then it's enabled on the serever and all variables will be
// automatically escaped with slashes. If it isn't true then it's done manually
if (!get_magic_quotes_gpc())
{
$title = addslashes($title);
$body = addslashes($body);
$date = addslashes($date);
}
// Connect to the database
$db = new mysqli('localhost','username','password','database');
// Check to see if the connection works
if ($db->connect_errno)
{
echo 'Error: Could not connect to database. Please try again.';
exit;
}
// Prepared statement for a query to place something in the database
if(!($stmt = $db->prepare("insert into pages (id, title, body, date) values (?,?,?,?)")))
{
echo "Prepare failed: (" .$db->errno . ")" . $db->error;
}
// THIS IS THE LINE WHERE I'M RECEIVING THE ERROR!!!!!!!!
if (!$stmt->bind_param('isss', ''.$id.'', ''.$title.'',''.$body.'',''.$date.''))
{
echo "Binding parameters failed: (" .$stmt->errno. ")" . $stmt->error;
}
if (!$stmt->execute())
{
echo "Execute failed: (" .$stmt->errno . ") " .$stmt->error;
}
$db->close;
?>
바인딩 호출하는 것입니다 param list는 auto_incrementing 필드이므로? – TommyBs
@ TommyBs 자동 증가 필드를 꺼낼 때 나는 여전히 같은 오류가 발생합니다. – cadavid4j
미안 해요. 첫 번째 의견은 PDO가 아닌, mysqli가 아니라고 생각해서 죄송합니다. bind_param 부분에서 변수 주위에 따옴표가 필요하지는 않습니다. 그러나 위에서 설명한대로 $ id를 제거하면 어떻게됩니까? – TommyBs