2015-11-07 121 views
2

我與PHP下拉菜單值

我的PHP已啓動

<?php 

mysql_select_db("$db") or die(mysql_error()); 

$sql = "SELECT kpi FROM pin_kpi_types"; 
$query = mysql_query($sql); 

echo '<select name="KPI" style="width: 400px">'; 
while ($row = mysql_fetch_assoc($query)) { 
    echo '<option>'.$row['KPI'].'</option>'; 
} 
echo '</select>'; 

?> 

,需要我手動輸入我的當前標籤/輸入法。

我想要做的是從表中拉出一個查詢來選擇唯一可用的KPI類型。

這是現在的工作。

<p> 
    <label for="KPIType" id="preinput">Choose KPI Type: </label> 
    <input type="text" name="kpi_type" required placeholder="Lead" id="inputid" /> 
</p> 

在那裏我是在以前


編輯;不幸的是,Lucky發佈的答案並不能幫助我,但它以正確的方式引導我。

我現在有重複的字段?它不會將值發佈到數據庫中。無論是。

下面是截圖...

http://s30.postimg.org/o1c2l9yr5/Untitled.png

有人能指導我在我出了問題的正確方向? :)

非常感謝您的幫助。

<?php 
    include('db.php'); 
     $select=mysql_query("SELECT * FROM pin_kpi_types"); 
     $i=1; 

    while($userrow=mysql_fetch_array($select)) 
     { 
     $kpi_id  =$userrow['KPI_ID']; 
     $kpi  =$userrow['KPI']; 
?> 
<style> 
#CreateStatusTypeFORM label {display: inline-block;width: 10em; text-align: right;padding-right: 0.5em;} 
</style> 

    <div id="CreateStatusTypeFORM"> 
    <form action="insert.php" method="post" name="insertform"> 
<p> 
    <div align='center'><label for="StatusColor" id="preinput">Choose A Color: </label> 
    <ui-colorpicker ng-model="targetColor"></ui-colorpicker></div> 
    <input type="hidden" name="pinstatus_color" value="{{targetColor}}" id="inputid" /> 
</p>  
<p> 
    <label for="StatusName" id="preinput">Set Status Name: </label> 
    <input type="text" name="pinstatus_type" required placeholder="Come Back" id="inputid"/> 
</p> 
<p> 
    <label for="StatusName" id="preinput">Available KPI Types: </label> 
    <select name="<?php echo $kpi; ?>" style="width: 237px"> 
    <option name="KPI" required id="inputid" value="<?php echo $kpi; ?>"><?php echo $kpi; ?></option> 
    </select> 
</p> 
<?php } ?> 
    <input type="submit" name="send" value="Submit" id="inputid1" /> 
</p> 
</form> 

我在哪裏現在所在的


這是我在哪裏。我現在可以正確地下拉下拉菜單而不會一遍又一遍地重複它。但是,現在我無法獲得將實際選定的KPI發佈到數據庫。一切都提交數據到分貝,但KPI_type option.

<style> 
.StatusForm {padding-left:75px;} 
.CreateStatusTypeFORM {padding:25px;border-style:solid; border-color:solid black; width: 500px;background-color:#C4C4C4;} 
#CreateStatusTypeFORM label {display: inline-block;width: 100em;} 
#CreateStatusTypeFORM input {border-color:solid black;} 
#CreateStatusTypeFORM input[type=text] {padding:5px; border:1px solid #666; -webkit-border-radius: 5px; border-radius: 5px;} 
</style> 
<div class='StatusForm'> 
    <div class="CreateStatusTypeFORM"> 
    <H3> ADD New Status </H3> 
    <form action="insert.php" method="post" name="insertform"> 
<p> 
    <label for="StatusColor" id="preinput">Choose A Color: </label> 
    <ui-colorpicker ng-model="targetColor"></ui-colorpicker> 
    <input type="hidden" name="pinstatus_color" value="{{targetColor}}" id="inputid" required placeholder=""/> 
</p>  
<p> 
    <label for="StatusName" id="preinput">Set Status Name: </label> 
    <input type="text" name="pinstatus_type" required placeholder="" id="inputid"/> 
</p> 
<p> 
    <label for="KPI" id="preinput">Available KPI Types: </label> 
    <select> 
    <?php 
    include('db.php'); 
     $select2=mysql_query("SELECT * FROM pin_kpi_types ORDER BY KPI_ID DESC"); 

    while($userrow=mysql_fetch_array($select2)) 
     { 
     $kpi   =$userrow['KPI']; 
     $kpi_id   =$userrow['KPI_ID'];   

?> 
<option name="kpi_type" required id="inputid" value="<?php echo $kpi; ?>"><?php echo $kpi; ?></option><?php } ?> 
    </select> 
</p> 
    <input type="submit" name="send" value="Submit" id="inputid1" /> 
</p> 
</form> 
</div> 
</div> 

這是插入功能。

<?php 
    ob_start(); 
     include("db.php"); 

     if(isset($_POST['send'])!="") 
      { 
       $pinstatus_type  =mysql_real_escape_string($_POST['pinstatus_type']); 
       $kpi_type  =mysql_real_escape_string($_POST['kpi_type']); 
       $pinstatus_color  =mysql_real_escape_string($_POST['pinstatus_color']); 
       $update   =mysql_query(" 
              INSERT INTO pin_status_types(
                   pinstatus_type, 
                   kpi_type, 
                   pinstatus_color, 
                   created 
                   ) 
                 VALUES(
                   '$pinstatus_type', 
                   '$kpi_type', 
                   '$pinstatus_color', 
                   now() 
                   ) 
               "); 

       if($update) 
       { 
       $msg="Successfully Updated!!"; 
        echo "<script type='text/javascript'>alert('$msg');</script>"; 
         header('Location:index.php'); 
       } 
       else 
       { 
       $errormsg="Something went wrong, Try again"; 
        echo "<script type='text/javascript'>alert('$errormsg');</script>"; 
       } 
      } 
     ob_end_flush(); 
?> 
+0

@Terminus我不繼。您是否介意做出調整並將其作爲答案發布,以便我可以看到我出錯的地方? – Kray

+0

你也可以給我們發送html輸出,它會告訴我們所有的表單和附加的類來找到重複的內容。 –

+0

@LeviZoesch爲什麼所有輸入元素的ID爲inputid? –

回答

2
mysql_select_db("$db") or die(mysql_error()); 

$sql = "SELECT kpi FROM pin_kpi_types"; 
$query = mysql_query($sql); 
echo '<label for="KPIType" id="preinput">Choose KPI Type: </label>'; 
echo '<select name="KPI" style="width: 400px" required id="inputid">'; 
echo '<option value=''>Lead</option>'; 
while ($row = mysql_fetch_assoc($query)) { 
echo '<option value='.$row['KPI'].'>'.$row['KPI'].'</option>'; 
} 
echo '</select>';