选中后,需要将我的下拉选项与数据库中的表链接

时间:2019-03-07 13:02:23

标签: php html phpmyadmin

我在名为“选择比赛”的下拉菜单中遇到一些麻烦,我需要这些比赛的名称与我的比赛ID链接,该ID在下面的表格中显示。从本质上讲,我需要从下拉菜单“类别”中获取用户输入,他们从中键入成员ID和“图像标题”的位置将用户输入,然后将它们放入我的数据库表中。

Screenshot of Database

<div class="row"> <!--Below I have again used the foldy grids with image tags that link to a waiting page -->
                        <div class="grid-2">
                        <p><b>Upload photo entries here!</b></p>
                        <form action = "" method = "POST" enctype="multipart/form-data">
                            <label>Select Competition</label>
                            <select name="Select Competition">
                            <option value="Default">Default</option>
                            <option value="1">Winter Warmer</option>
                            <option value="2">Fresh New Year</option>
                            <option value="3">Month of Love</option>
                            <option value="4">Seaside Scenery</option>
                            </select>
                        </fieldset>

                        <label>Enter Member ID</label>
                            <input type ="text" name ="member-id" placeholder="Enter Your Member ID...">
                            <label>Enter Title</label> 
                            <input type ="text" name ="img-title" placeholder="Enter Title...">
                          <table width="300" border="0" cellpadding="1" cellspacing="1" class="box">
                            <tr> 
                              <td width="246">
                                <input type="hidden" name="MAX_FILE_SIZE" value="2000000"> <!-- 2 Megabytes -->
                                <input name="userfile" type="file" id="userfile"> 
                              </td>
                              <td width="80">
                                <input name="upload" type="submit" id="upload" value="Upload "> <!-- A button -->
                              </td>
                            </tr>
                          </table>
                        </form>

                        <?php
                        $uploadDir = 'images/';


                        if(isset($_POST['upload']))
                        {
                          $fileName = $_FILES['userfile']['name'];
                          $tmpName = $_FILES['userfile']['tmp_name'];
                          $fileSize = $_FILES['userfile']['size'];
                          $fileType = $_FILES['userfile']['type'];
                          $memberID = $_POST['member-id'];
                          $imgTitle = $_POST['img-title'];
                          $catID = $_POST['catID'];

                          $filePath = $uploadDir . $fileName;

                          $result = move_uploaded_file($tmpName, $filePath);

                          if (!$result) {
                            echo "Error uploading file";
                    exit;
                  }

                  echo "<br>Files uploaded<br>";

                if(mysqli_connect_errno())
                {
                  printf("Connect failed: %s\n", mysqli_connect_error());
                    exit();
                }

                if(!get_magic_quotes_gpc())
                {
                $fileName = addslashes($fileName);
                $filePath = addslashes($filePath);
                } 


                $query = "INSERT INTO `tblImage` (`fldImageID`, `fldMemberID`, `fldCatID`, `fldFilePath`, `fldName`) VALUES (NULL, '$memberID', '$catID', '$filePath', '$imgTitle')";

                // echo $query;
                $result = $conn->query($query) or die ("error");

                }

                  ?>
                </div>

屏幕上出现的错误是:

Error on the html page

1 个答案:

答案 0 :(得分:1)

您可能会使用<select name="catID">

类似这样的东西:

<select name="catID">
  <option value="">Select Competition</option>
  <option value="Default">Default</option>
  <option value="1">Winter Warmer</option>
  <option value="2">Fresh New Year</option>
  <option value="3">Month of Love</option>
  <option value="4">Seaside Scenery</option>
</select>