好吧,我知道這隻能是一些逗號或括號丟失,但對於我的生活,我沒有看到它。我是PHP的新手,所以也許這是別的。我有一個函數在另一個腳本中工作,它只是函數名稱($ variables){code}那麼爲什麼不在這裏工作?解析錯誤:語法錯誤,意想不到的T_FUNCTION ...在第4行
謝謝你找到我愚蠢的錯誤 - 如果它是一個。
Display.php的
<?php
require('database.php');
require('product_list.php');
require('addprod.php');
$productIDtx = $_POST['productIDtx'];
$categoryIDtx = $_POST['categoryIDtx'];
$productCodetx = $_POST['productCodetx'];
$productNametx = $_POST['productNametx'];
$listPricetx = $_POST['listPricetx'];
$categoryNametx = $_POST['categoryNametx'];
if(isset($_POST['tableName']))
{
$table = $_POST['tableName'];
}
else
{
echo("Must select a table.<br>");
}
if(isset($_POST['operation']))
{
$operation = $_POST['operation'];
}
else
{
echo("Must select an action.<br>");
exit();
}
if($operation == 'addition')
{
if($table == 'products')
{
include_once('addprod.php');
add_products($productIDtx, $categoryIDtx, $productCodetx, $productNametx, $listPricetx);
}
}
?>
addprod.php
<?php
include('database.php')
//**LINE 4 IS THE LINE BELOW**
function add_products($productIDtx, $categoryIDtx, $productCodetx, $productNametx, $listPricetx, $categoryNametx) // **THIS IS LINE 4**
{
global $db;
if (empty($productIDtx) || empty($categoryIDtx) || empty($productCodetx) || empty($productNametx) || empty($listPricetx))
{
$error = "Invalid product data. Check all fields and try again.";
echo ($error);
}
else
{
$query = "INSERT INTO products (productID, categoryID, productCode, productName, listPrice)
VALUES ('$productIDtx', '$categoryIDtx', '$productCodetx', '$productNametx', '$listPricetx')";
$insert = $db->exec($query);
}
if ($insert < 1)
{
echo ("<p>No records added. Make sure values are valid and productID is unique.</p>");
exit();
}
$theQuery = "SELECT * FROM products order by productID";
$rSet = $db -> query($theQuery);
$list = "";
}
?>
<!DOCTYPE html>
<html>
<header><title>Products</title></header>
<body>
<?php require('menu.html');?>
<table border="1">
<?php
$list = "<tr><td>productID</td><td>categoryID</td><td>productCode</td><td>productName</td><td>List Price</td></tr>";
foreach($rSet AS $products)
{
$list .= "<tr><td>".$products['productID']."</td>"
."<td>".$products['categoryID']."</td>"
."<td>".$products['productCode']."</td>"
."<td>".$products['productName']."</td>"
."<td>".$products['listPrice']."</td>"
."</tr>";
}
echo($list);
?>
</table>
</body>
</html>
你錯過了上面一行的分號 –