我的add.php出现500 Server错误

时间:2015-12-31 17:44:47

标签: php mysql mysqli

所以我正在创建条形码库存系统。我在添加到数据库页面时遇到问题,该页面给了我一个"服务器错误500"。我忽略了什么吗?

add.php

include('dbconnect.php');
function get_posts() {
$txtitemcode = (!empty($_POST['itemcode']) ? $_POST['itemcode'] : null);
$txtitem = (!empty($_POST['item']) ? $_POST['item'] : null);
$txtqty = (!empty($_POST['qty']) ? $_POST['qty'] : null);
$txtsrp = (!empty($_POST['srp']) ? $_POST['srp'] : null);
$txtmarkuprate = (!empty($_POST['markuprate']) ? $_POST['markuprate'] : null);
$txtsp = ($txtsrp*$txtmarkuprate)+$txtsrp;
$sql = "INSERT INTO barcode(itemcode, item, qty, srp, markup, sp) VALUES ('".$txtitemcode"','".$txtitem."','".$txtqty."','".$txtsrp."','".$txtmarkuprate."','".$txtsp."')";
if(!mysqli_query($con, $sql))
{
die('Error:'.mysqli_error());
}
echo "<h1>record added</h1>;
window.location.href='index.php';</script>";
}

mysqli_close($con);

dbconnect.php

$con = mysqli_connect("localhost","root","password","db1");

// Check connection
if (mysqli_connect_errno())
  {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
  else
  {
    echo "it worked";
  }

1 个答案:

答案 0 :(得分:2)

我认为你错过了一个点".$txtitemcode"

更新此行:

$sql = "INSERT INTO barcode(itemcode, item, qty, srp, markup, sp) VALUES ('".$txtitemcode"','".$txtitem."','".$txtqty."','".$txtsrp."','".$txtmarkuprate."','".$txtsp."')";

到这一行:

$sql = "INSERT INTO barcode(itemcode, item, qty, srp, markup, sp) VALUES ('".$txtitemcode."','".$txtitem."','".$txtqty."','".$txtsrp."','".$txtmarkuprate."','".$txtsp."')";