好的,我知道这只是一些逗号或括号丢失,但对于我的生活,我看不到它。我是PHP的新手,所以也许是其他的东西。我有一个函数在另一个脚本中工作,它只是函数名称($ variables){code}那么为什么不在这里工作???
感谢您找到我的愚蠢错误 - 如果它是一个错误。
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>
答案 0 :(得分:0)
addprod.php - 第2行
include('database.php')
缺少分号。这就是为什么以下功能是意外的