Tôi đang gặp sự cố với PDO. Ở đầu index.php của tôi, tôi có những điều sau:
<?php
session_start();
// start of script every time.
// setup a path for all of your canned php scripts
$php_scripts="/home/foxclone/php/"; // a folder above the web accessible tree
// load the pdo connection module
require $php_scripts . 'PDO_Connection_Select.php';
require $php_scripts . 'GetUserIpAddr.php';
//*******************************
// Begin the script here
$ip = GetUserIpAddr();
if (!$pdo = PDOConnect("foxclone_data")):
{
echo "Failed to connect to database" ;
exit;
}
else:
{
$sql = "INSERT INTO Downloads (ip_address,filename) VALUES ('$ip','$down')";
// use exec() because no results are returned
$pdo->exec($sql);
}
endif;
//exit();
?>
Đi sâu hơn vào index.php Tôi có một phần tải xuống mà tôi muốn ghi lại trong cùng một bảng:
<?php
$files = glob('download/*.iso');
$file = $files[count($files) -1];
$filename = basename($file);
$md5file = md5_file($file);
?>
<div class="container">
<div class="divL">
<h3>Get the "https://forum.freecodecamp.org/t/problem-with-pdo-in-php-page/<?php echo"{$filename}";?>" file (approx. 600MB)</h3>
<center> <a href="https://forum.freecodecamp.org/t/problem-with-pdo-in-php-page/<?php echo"/{$file}";?>"><img src="images/button_get-the-app.png" alt=""></a> </center>
<?php
$down=$filename
$sql = "INSERT INTO Downloads (ip_address,filename) VALUES ('$ip','$down')"; <-- parse error here
$pdo->exec($sql);
?>
Tôi đang gặp phải lỗi sau: Lỗi phân tích cú pháp: lỗi cú pháp, ‘$sql’ (T_VARIABLE) không mong muốn trong /home/foxclone/test.foxclone.com/index.php nhưng không hiểu tại sao. Tôi có cần dòng $sql không?
Cảm ơn trước,
Larry
Có vẻ như bạn vừa bỏ sót dấu chấm phẩy ở dòng trước.
Cảm ơn vì đã nắm bắt được điều đó.