0

我正在编辑我的网站,并且在我的管理部分中我正在创建一个 CMS。

在我的 ADD.PHP 中,我添加了一些字段。这些字段有效,但今天我决定将上传添加到图像字段。

我的 ADD.PHP 代码是这样的:

<?php

session_start();

include_once('../include/connection.php');

if (isset($_SESSION['logged_in'])){
      if (isset($_POST['title'], $_POST['content'])) {
             $title = $_POST['title'];
             $content = nl2br($_POST['content']);
             $image = $_POST['image'];
             $link = $_POST['link'];
             $category = $_POST['category'];
             $brand = $_POST['brand'];

if (empty($title) or empty($content)) {
             $error = 'All Fields Are Required!';
}else{
     $query = $pdo->prepare('INSERT INTO mobi (promo_title, promo_content, promo_image, promo_link, promo_cat, promo_name) VALUES(?, ?, ?, ?, ?, ?)');
     $query->bindValue(1, $title);
     $query->bindValue(2, $content);
     $query->bindValue(3, $image);
     $query->bindValue(4, $link);
     $query->bindValue(5, $category);
     $query->bindValue(6, $brand);

     $query->execute();
    header('location: index.php');
}

}
          ?>

<html>
<head>
<title>Add Article</title>
<link rel="stylesheet" href="../other.css" />
</head>

<body>
<div class="container">
<a href="index.php" id="logo"><b>&larr; Back</b></a>

<br />

<div align="center">
<h4>Add Article</h4>

<?php if (isset($error)) { ?>
     <small style="color:#aa0000;"><?php echo $error; ?></small><br /><br />
<?php } ?>

<form action="add.php" method="post" autocomplete="off">

<input type="text" name="title" placeholder="Title" /><br /><br />
<textarea rows="15" cols="50" placeholder="Content" name="content"></textarea><br /><br />
<input name="image" type="file" id="image" />
<input type="text" name="image" placeholder="Image" /><br /><br />
<input type="link" name="link" placeholder="Link" /><br /><br />
<input type="category" name="category" placeholder="Category" /><br /><br />
<input type="category" name="brand" placeholder="Brand" /><br /><br />
<input type="submit" value="Add Article" />

</form>
</div>
</div>
</body>
</html>


<?php
}else{
       header('location: index.php');
}

?> 

如您所见,我有一个选择框,然后是图像的文本框。

我想要的是将其中一个或另一个添加到同一字段中。举个例子。

如果我的计算机上有图像,那么我将使用“选择文件”按钮选择文件。但是,如果我想使用网络图像,那么我会将其输入图像框中。

但我希望这两个选项都添加到同一个 promo_link 数据库字段中。

我只想选择一个。

我怎样才能做到这一点?

请帮忙。谢谢你。

4

0 回答 0