2017-07-08 4 views
0

このドロップダウンの値をSQLテーブルフィールドに書き込む必要があるPHPフォームへのドロップダウンを作成します。SQLテーブルフィールドへのドロップダウン値の書き込み

私はほとんどの問題はこの作品name="txtStatus" value="<?php echo $dataSt['Opt'];?>">ですが、私はそれを動作させることはできません特定されています。今、私は仕事に、ダウンページで、ドロップダウンを取得することができるよしかし$result["Status"]の値がsave.phpファイルに送信されず、もちろんどちらも、edit.phpのコード この編集

SQLデータベース表のフィールドに入力します。

<html> 
<head> 
<title>TEST EDIT</title> 
</head> 
<style type="text/css"> 
@import url(http://fonts.googleapis.com/css?family=Roboto:400,500,700,300,100); 
body { 
    background-color: #576370; 
    font-family: "Roboto", helvetica, arial, sans-serif; 
    font-size: 16px; 
    font-weight: 400; 
    text-rendering: optimizeLegibility; 
} 

div.table-title { 
    text-align:center; 
    display: block; 
    margin: auto; 
    width: 100%; 
} 

.table-title h3 { 
    color: #fafafa; 
    padding:1px; 
    font-size: 25px; 
    font-weight: 300; 
    font-style:normal; 
    font-family: "Roboto", helvetica, arial, sans-serif; 
    text-shadow: -1px -1px 1px rgba(0, 0, 0, 0.1); 
    text-transform:uppercase; 
} 

.table-title h2 { 
    color: #D8D8D8; 
    font-size: 10px; 
    font-weight: 50; 
    font-style:normal; 
    text-transform:uppercase; 
} 

.table-title h4 { 
    color: #F3F781; 
    font-size: 10px; 
    font-weight: 50; 
    font-style:normal; 
    text-transform:uppercase; 
} 

/*** Table Styles **/ 

.table-fill { 
    background: white; 
    border-radius:3px; 
    border-collapse: collapse; 
    height: 15px; 
    margin: auto; 
    padding:1px; 
    width: 100%; 
    box-shadow: 0 5px 10px rgba(0, 0, 0, 0.1); 
    animation: float 8s infinite; 
} 

th { 
    color:#D5DDE5; 
    text-align:left; 
    background:#1b1e24; 
    border-right: 1px solid #343a45; 
    font-size:14px; 
    font-weight: 50; 
    padding:8px; 
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.1); 
    vertical-align:middle; 
    width: 100px; 
} 

th:first-child { 
    border-top-left-radius:3px; 

} 

th:last-child { 
    border-top-right-radius:3px; 
    border-right:none; 
} 

tr { 
    border-top: 1px solid #C1C3D1; 
    border-bottom-: 1px solid #C1C3D1; 
    color:#666B85; 
    font-size:16px; 
    font-weight:normal; 
    text-shadow: 0 1px 1px rgba(256, 256, 256, 0.1); 
} 

tr:hover td { 
    background:#4E5066; 
    color:#FFFFFF; 
    border-top: 0px solid #22262e; 
    border-bottom: 0px solid #22262e; 
} 

tr:first-child { 
    border-top:none; 
} 

tr:last-child { 
    border-bottom:none; 
} 

tr:nth-child(odd) td { 
    background:#EBEBEB; 
} 

tr:nth-child(odd):hover td { 
    background:#4E5066; 

} 

tr:last-child td:first-child { 
    border-bottom-left-radius:3px; 
} 

tr:last-child td:last-child { 
    border-bottom-right-radius:3px; 
} 

td { 
    background:#FFFFFF; 
    padding:8px; 
    vertical-align:middle; 
    font-weight:300; 
    font-size:14px; 
    text-shadow: -1px -1px 1px rgba(0, 0, 0, 0.1); 
    border-right: 1px solid #C1C3D1; 
} 

.show {display:block;} 
</style> 
</head> 
<body> 
<div class="table-title"> 
    <h3>SCANIA FINANCE</h3> 
<body> 

<?php 
    ini_set('display_errors', 1); 
    error_reporting(~0); 

    $serverName = 'localhost'; 
    $userName = 'user'; 
    $userPassword = 'password'; 
    $dbName = 'AdWorks'; 

    $strBusinessEntityID = null; 

    if(isset($_GET["BusinessEntityID"])) 
    { 
     $strBusinessEntityID = $_GET["BusinessEntityID"]; 
    } 

    $connectionInfo = array("Database"=>$dbName, "UID"=>$userName, "PWD"=>$userPassword, "MultipleActiveResultSets"=>true); 

    $conn = sqlsrv_connect($serverName, $connectionInfo); 

    if($conn === false) { 
     die(print_r(sqlsrv_errors(), true)); 
    } 

    $stmt = "SELECT * FROM tKelvin32 WHERE BusinessEntityID = ? "; 
    $params = array($strBusinessEntityID); 

    $query = sqlsrv_query($conn, $stmt, $params); 

    $result = sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC); 


?> 
<form action="save_bck.php" name="frmAdd" method="post"> 
<table align="center"> 
    <tr> 
    <th width="120">BusinessEntityID</th> 
    <td><input type="hidden" name="txtBusinessEntityID" value="<?php echo $result["BusinessEntityID"];?>"><?php echo $result["BusinessEntityID"];?></td> 
    </tr> 
    <tr> 
    <th width="120">FirstName</th> 
    <td><input type="hidden" name="txtFirstName" value="<?php echo $result["FirstName"];?>"><?php echo $result["FirstName"];?></td> 
    </tr> 
    <tr> 
    <th width="120">LastName</th> 
    <td><input type="hidden" name="txtLastName" size="25" value="<?php echo $result["LastName"];?>"><?php echo $result["LastName"];?></td> 
    </tr> 
    <tr> 
    <th width="120">JobTitle</th> 
    <td><input type="hidden" name="txtJobTitle" value="<?php echo $result["JobTitle"];?>"><?php echo $result["JobTitle"];?></td> 
    </tr> 
    <tr> 
    <th width="120">PhoneNumber</th> 
    <td><input type="hidden" name="txtPhoneNumber" value="<?php echo $result["PhoneNumber"];?>"><?php echo $result["PhoneNumber"];?></td> 
    </tr> 
    <tr> 
    <th width="120">PhoneNumberType</th> 
    <td><input type="hidden" name="txtPhoneNumberType" value="<?php echo $result["PhoneNumberType"];?>"><?php echo $result["PhoneNumberType"];?></td> 
    </tr> 
    <tr> 
    <th width="120">EmailAddress</th> 
    <td><input type="hidden" name="txtEmailAddress" value="<?php echo $result["EmailAddress"];?>"><?php echo $result["EmailAddress"];?></td> 
    </tr> 
    <tr> 
    <th width="120">AddressLine1</th> 
    <td><input type="hidden" name="txtAddressLine1" value="<?php echo $result["AddressLine1"];?>"><?php echo $result["AddressLine1"];?></td> 
    </tr> 
    <tr> 
    <th width="120">City</th> 
    <td><input type="hidden" name="txtCity" value="<?php echo $result["City"];?>"><?php echo $result["City"];?></td> 
    </tr> 
    <tr> 
    <th width="120">PostalCode</th> 
    <td><input type="hidden" name="txtPostalCode" value="<?php echo $result["PostalCode"];?>"><?php echo $result["PostalCode"];?></td> 
    </tr> 
    <tr> 
    <th width="120">CountryRegionName</th> 
    <td><input type="hidden" name="txtCountryRegionName" value="<?php echo $result["CountryRegionName"];?>"><?php echo $result["CountryRegionName"];?></td> 
    </tr> 
    <tr> 
    <th width="120">Status</th> 
    <td> 
    <input type="hidden" name="txtStatus" value="<?php echo $result["Status"];?>"><select name="TowerSelect"><option> Choose </option> 
    <?php 
    //STATUS Query 
    $sqlSt = "SELECT DISTINCT Opt FROM StatsOptions ORDER BY Opt"; 
    $resultSt = sqlsrv_query($conn,$sqlSt) or die("Couldn't execut query"); 
    while ($dataSt=sqlsrv_fetch_array($resultSt, SQLSRV_FETCH_ASSOC)){ 
    echo '<option value="'.$dataSt['Opt'].'">'; 
    echo $dataSt['Opt']; 
    echo "</option>"; 
    } 
    ?> 
    </select> 
    </td> 
    </tr> 
    </table> 
    <input type="submit" name="submit" value="submit"> 
</form> 
<?php 
sqlsrv_close($conn); 
?> 
</body> 
</html> 
+0

エラーが発生していますか? – lalithkumar

+0

@Kelvin Morel、あなたは隠された値を投稿する必要がありますか、隠しフィールドでデータを取得したいですか? – Sahathulla

+0

ドロップダウンから値を選択できるはずです。この値はフィールドをSQLテーブルに更新する必要があります。私はこのコードを本当によく分かりません。 –

答えて

1

選択タグを閉じるのは忘れてしまいます。 PHPタグを閉じた後、選択タグを閉じます。

...</select>.... 

フォームの送信後にドロップダウン値が表示されるかどうかを確認してください。

0

[OK]を、私はそれを得た、問題はedit_bck.phpコードではありませんでしたが、save.phpコードの上に、私は間違った変数を呼んでいた、私は次のコードを参照してください、$_POST["txtStatus"]代わりの$_POST["Desc"]を呼んでいました。

if($conn === false) { 
     die(print_r(sqlsrv_errors(), true)); 
    } 

    $sql = "UPDATE tKelvin32 SET 
       FirstName = ? , 
       LastName = ? , 
       JobTitle = ? , 
       PhoneNumber = ? , 
       PhoneNumberType = ?, 
       EmailAddress = ?, 
       AddressLine1 = ?, 
       City = ?, 
       PostalCode = ?, 
       CountryRegionName = ?, 
       Status = ? 
       WHERE BusinessEntityID = ? "; 

    $params = array($_POST["txtFirstName"], $_POST["txtLastName"], $_POST["txtJobTitle"], $_POST["txtPhoneNumber"], $_POST["txtPhoneNumberType"], $_POST["txtEmailAddress"], $_POST["txtAddressLine1"], $_POST["txtCity"], $_POST["txtPostalCode"], $_POST["txtCountryRegionName"], $_POST["Desc"],$_POST["txtBusinessEntityID"]); 
+0

今すぐ解決されました。 @ケルビン – Sahathulla

+0

@Sahathulla、はい、確かに! –

関連する問題