我制作了这个表单,它连接到其他PHP文件,除了这个表单之外,所有文件都像预期的那样工作。
我验证了名为addproducts.php的文件,除了我应该为cellpadding
&CCD_ 2。该表单基于我先前创建的另一个表单,该表单也具有关于CCD_;spacing
,尽管这种形式很好用。但这个新表单什么也不显示,页面只是一片空白。新形式
我的目标应该是这样的(我的第一种形式)结果(我为代码中的瑞典评论道歉。)
我真诚地感谢在这件事上给予的任何帮助。
<?php
include_once "../db_connect.php";
include_once "html_headers.php";
error_reporting(0);
session_start();
$logged_in = (isset($_SESSION['login']) && $_SESSION['login'] != '');
if($logged_in) {
if(isset($_SESSION['access']) && $_SESSION['access'] == 'admin') {
echo rapport_header();
echo "<div class=adminheader><h2>Lägg till produkt</h2><a href='../index.php'>Förstasidan</a></div>";
}
}
if(isset($_POST['spara'])){
$id = $_POST['id'];
$produktnummer = $_POST['produktnummer'];
$produktnamn = $_POST['produktnamn'];
$beskrivning = $_POST['beskrivning'];
$pris = $_POST['pris'];
$produktbild = $_POST['produktbild'];
$lagersaldo = $_POST['lagersaldo'];
$type = $_POST['type'];
$isonoffer = $_POST['isonoffer'];
$sql = "INSERT INTO produkter (id,produktnummer,produktnamn,beskrivning,pris,produktbild,lagersaldo,type,isonoffer) VALUES ('$id','$produktnummer','$produktnamn','$beskrivning','$pris','$produktbild','$lagersaldo','$type','$isonoffer')";
if($mysqli = connect_db()) {
$mysqli->query($sql);
print_r($mysqli->error);
}
echo "Produkten är nu inlagd i databasen<br />";
echo "<a href='products.php'>Tillbaka till listningssidan</a>";
}
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Lägg till en produkt</title>
</head>
<body>
<form action="addproducts.php" method="post">
<table cellpadding="3" cellspacing="0" border="1">
<tr><td>id</td><td><input type="number" name="id" /></td></tr>
<tr><td>produktnummer</td><td><input type="text" name="produktnummer" /></td></tr>
<tr><td>produktnamn</td><td><input type="text" name="produktnamn" /></td></tr>
<tr><td>beskrivning</td><td><input type="text" name="beskrivning" /></td></tr>
<tr><td>pris</td><td><input type="text" name="pris" /></td></tr>
<tr><td>produktbild</td><td><input type="text" name="produktbild" /></td></tr>
<tr><td>lagersaldo</td><td><input type="number" name="lagersaldo" /></td></tr>
<tr><td>type</td><td><input type="text" name="type" /></td></tr>
<tr><td>isonoffer</td><td><input type="text" name="isonoffer" /></td></tr>
<tr><td colspan="2"><input type="submit" name="spara" value="Spara" />
</table>
</form>
</body>
</html>
只需检查Web服务器错误日志或打开错误报告即可查看问题。
我想问题出在你的include_once
上。您应该使用绝对路径。
更改:
include_once "../db_connect.php";
include_once "html_headers.php";
收件人:
include_once __DIR__ . "/../db_connect.php";
include_once __DIR__ . "/html_headers.php";