dongpenggan6812 2015-11-20 03:10
浏览 17
已采纳

使用php在下拉菜单中缩写状态

I'm back once again, I know you guys are probably tired of me lol but there are somethings I figured out how to add the text boxes. I am still having trouble with the drop down menu. I am supposed to have a drop down menu that has the list of the states and when you submit it, it will be abbreviated but that doesn't want to work for me either. I'm pretty sure it is something easy to fix and I keep over looking it.

 <!DOCTYPE html>
<html>
    <head>
        <title>Lab 7, Part 1</title>
        <meta charset="UTF-8"/>
        <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    </head>
    <body>
        <form name="myform" action="http://weblab.kennesaw.edu/formtest.php"
        onsubmit="return validateForm()"
              method = "post">
        <h1 style="text-align:center">Lab 7, Part 1</h1>
        <h2 style="text-align:center">IT 3203</h2>
        <a href="index.html"><p style="text-align:center">Main Page!</p></a>
        <table>
        <th>Fruits For Sale!</th>
        <tr><th>Fruits</th><th>Weight</th><th>Price</th></tr>
         <?php
        $db=mysqli_connect(null,null,null,'weblab')
or die("Can't connect to DB:" . mysqli_connect_error());
        $q = " select fruit_item_no, fruit_name, fruit_weight, fruit_price";
        $q .= " from fruit_t";
        $q .= " order by fruit_name;";
        $dbResult = mysqli_query($db,$q);
        $num = mysqli_num_rows($dbResult);
        if ($num == 0) {
         echo '<tr><td colspan="2">';
        echo 'Database query retrieved zero rows.</td></tr>';
}
 while ($row = mysqli_fetch_assoc($dbResult)) {
        $name = $row['fruit_name'];
        $weight = $row['fruit_weight'];
        $price = $row['fruit_price'];
        echo "<tr><td><b>$name</b></td>";
        echo "<td>$weight</td>";
        echo "<td>$price</td>";
        echo "<td><input type='text' name='name'></td></tr>
";
}
?>
</table>
        <br>
        <label>First Name
            <input type="text"
                   name="firstname" id="firstname"
                   size="25" />
        </label>
        <br>
        <br>
        <label>Last Name
 <input type="text"
                   name="lastname" id="lastname"
                   size="25" />
        </label>
        <br>
        <br>
        <label>Street Address
            <input type="text"
                   name="streetaddress" id="streetaddress"
                   size="35" />
  </label>
        <br>
        <br>
        <label>City
            <input type="text"
                   name="city" id="city"
                   size="25" />
        </label>
        <label>State:
    <select name="state" id="state">
  <?php
    $db=mysqli_connect(null,null,null,'weblab')
     or die("Can't connect to DB:" . mysqli_connect_error());
    $q = " select state_abbr, state_name";
    $q .= " from state_t";
    $q .= " order by state_name;";
    while ($x = mysqli_fetch_assoc($dbResult)) {
    $state_abbr = $x["state_abbr"];
    $state_name = $x["state_name"];
?>
<option value="<?php echo $state_abbr; ?>">
    <?php echo $state_name; ?></option>
<?php
}
?>
        </select>
<?php
}
?>
</label>
 <br>
        <br>
        <label>Zip code:
            <input type="text"
                   name="zipcode" id="zipcode"
                   size="20" />

        </label>
        <br>
        <br>
<label>Visa
            <input type="radio" name="pref_payment"
                   id="pref_payment_visa" value="visa" checked />
        </label><br>
        <label>MasterCard
            <input type="radio" name="pref_payment"
                   id="pref_payment_master" value="master" checked />
        </label><br>
        <label>American Express
            <input type="radio" name="pref_payment"
 id="pref_payment_american" value="american" checked />
        </label><br>
        <input type="submit" value="Submit!">
        </form>
    </body>
</html>
  • 写回答

2条回答 默认 最新

  • doupiao1893 2015-11-20 04:15
    关注

    That is why code indentation is so important.. You were missing closing PHP tags at two places. Refer to below code.

    <!DOCTYPE html>
    <html>
        <head>
            <title>Lab 7, Part 1</title>
            <meta charset="UTF-8"/>
            <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
        </head>
        <body>
            <form name="myform" action="http://weblab.kennesaw.edu/formtest.php" onsubmit="return validateForm()" method = "post">
    
                <h1 style="text-align:center">Lab 7, Part 1</h1>
                <h2 style="text-align:center">IT 3203</h2>
                <a href="index.html"><p style="text-align:center">Main Page!</p></a>
                <table>
                    <th>Fruits For Sale!</th>
                    <tr><th>Fruits</th><th>Weight</th><th>Price</th></tr>
                    <?php
                        $db = mysqli_connect(null,null,null,'weblab')
                            or die("Can't connect to DB:" . mysqli_connect_error());
                        $q = " select fruit_item_no, fruit_name, fruit_weight, fruit_price";
                        $q .= " from fruit_t";
                        $q .= " order by fruit_name;";
                        $dbResult = mysqli_query($db,$q);
                        $num = mysqli_num_rows($dbResult);
                        if ($num == 0) 
                        {
                            echo '<tr><td colspan="2">';
                            echo 'Database query retrieved zero rows.</td></tr>';
                        }
                        while ($row = mysqli_fetch_assoc($dbResult)) 
                        {
                            $name = $row['fruit_name'];
                            $weight = $row['fruit_weight'];
                            $price = $row['fruit_price'];
                            echo "<tr><td><b>$name</b></td>";
                            echo "<td>$weight</td>";
                            echo "<td>$price</td>";
                            echo "<td><input type='text' name='name'></td></tr>
    ";
                        }
                    ?>
                </table>
                <br>
                <label>First Name
                    <input type="text" name="firstname" id="firstname" size="25" />
                </label>
                <br>
                <br>
                <label>Last Name
                    <input type="text" name="lastname" id="lastname" size="25" />
                </label>
                <br>
                <br>
                <label>Street Address
                    <input type="text" name="streetaddress" id="streetaddress" size="35" />
                </label>
                <br>
                <br>
                <label>City
                    <input type="text" name="city" id="city" size="25" />
                </label>
                <label>State:
                    <select name="state" id="state">
                        <?php
                            $db = mysqli_connect(null,null,null,'weblab')
                                or die("Can't connect to DB:" . mysqli_connect_error());
                            $q = " select state_abbr, state_name";
                            $q .= " from state_t";
                            $q .= " order by state_name;";
                            $dbResult_state = mysqli_query($db,$q);
                            while ($x = mysqli_fetch_assoc($dbResult_state))  
                            {
                                $state_abbr = $x["state_abbr"];
                                $state_name = $x["state_name"];
                                ?>
                                <option value="<?php echo $state_abbr; ?>">
                                <?php echo $state_name; ?></option>
                                <?php
                            } ?>
                    </select>
                    <?php } ?> <!-- remove this -->
                </label>
                <br>
                <br>
                <label>Zip code:
                    <input type="text" name="zipcode" id="zipcode" size="20" />
                </label>
                <br>
                <br>
                <label>Visa
                    <input type="radio" name="pref_payment" id="pref_payment_visa" value="visa" checked />
                </label>
                <br>
                <label>MasterCard
                    <input type="radio" name="pref_payment" id="pref_payment_master" value="master" checked />
                </label>
                <br>
                <label>American Express
                    <input type="radio" name="pref_payment" id="pref_payment_american" value="american" checked />
                </label>
                <br>
                <input type="submit" value="Submit!">
            </form>
        </body>
    </html>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 C语言设计一个简单的自动换档程序
  • ¥15 关于logstash转发日志时发生的部分内容丢失问题
  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。