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');
}

?> 

ご覧のとおり、画像用の選択ボックスとテキスト ボックスの両方があります。

私が望むのは、どちらか一方が同じフィールドに追加されることです。たとえば。

コンピューターに画像がある場合は、[ファイルを選択] ボタンを使用してファイルを選択します。しかし、Web 画像を使用したい場合は、画像ボックスに入力します。

しかし、両方のオプションを同じ promo_link データベース フィールドに追加したいと考えています。

1人だけ選んでほしい。

これどうやってするの?

助けてください。ありがとうございました。

4

0 に答える 0