与mysql交互的html下拉菜单

时间:2015-12-17 13:54:46

标签: php html mysql html-table

我最近在我的网站的index.php中更改了我的代码,现在mysql下拉菜单无效。它带我回到主页,而不是mysql中表的其他页面。我很可能删除了一些东西,但我不确定是什么。这是我的index.php html代码:

<form method="post" action="http://www.450s.co/index.php">
    <table border="0" width="100%">
        <tbody>
            <tr>
                <td>
                    <p style="font-family: 'Arial'; color: black;">Select your town/city:</p>
                    <select id="change_city" name="city" class="dropdown-style center">
                        <option value="24">Bedfordshire</option>
                        <option value="46">Buckinghamshire</option>
                        <option value="5" selected="">Greater London</option>
                        <option value="39">Hertfordshire</option>
                        <option value="44">Lincolnshire</option>
                        <option value="45">Northamptonshire</option>
                        <option value="47">Nottinghamshire</option>
                        <option value="23">Oxfordshire</option>
                        <option value="42">Reigate</option>
                        <option value="41">Slough</option>
                        <option value="40">St Albans</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>
                    <p style="font-family: arial; color: black;">Select your postcode:</p>
                    <select name="code" id="change_postcode" class="dropdown-style">
                        <option value="1">BR - Bromley</option>
                        <option value="2">CR - Croyden</option>
                        <option value="3">DA - Dartford</option>
                        <option value="4">E - East London</option>
                        <option value="5">EC - City of London</option>
                        <option value="6">EN - Enfield</option>
                        <option value="7">HA - Harrow</option>
                        <option value="8">IG - Ilford</option>
                        <option value="9">KT - Kingston upon Thames</option>
                        <option value="10">N - North London</option>
                        <option value="11">NW - North West London</option>
                        <option value="12">RM - Romford</option>
                        <option value="13">SE - South East London</option>
                        <option value="14">SM - Sutton</option>
                        <option value="15">SW - South West London</option>
                        <option value="16">TW - Twickenham</option>
                        <option value="17">UB - Southall</option>
                        <option value="18">W - West End</option>
                        <option value="19">WC - West Central</option>
                        <option value="20">WD - Watford</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>
                    <p style="font-family: arial; color: black;">Select your trade:</p>
                    <select name="cat" class="dropdown-style center">
                        <option value="1">Aerials</option>
                        <option value="2">Air Conditioning</option>
                        <option value="3">Airport Transfers</option>
                        <option value="58">Architectural Services</option>
                        <option value="4">Auto Electricians</option>
                        <option value="5">Bathrooms</option>
                        <option value="6">Beauty Salons</option>
                        <option value="7">Bedrooms</option>
                        <option value="8">Blinds and Curtains</option>
                        <option value="9">Boilers</option>
                        <option value="10">Brake and Clutch</option>
                        <option value="11">Builders</option>
                        <option value="12">Burglar Alarms</option>
                        <option value="13">Car Body Repairs</option>
                        <option value="14">Car Hire</option>
                        <option value="15">Carpenters</option>
                        <option value="16">Carpet Cleaning</option>
                        <option value="17">Carpet Fitting</option>
                        <option value="18">Central Heating</option>
                        <option value="20">Chiropodists</option>
                        <option value="51">Chiropractors</option>
                        <option value="22">Cleaning Services</option>
                        <option value="59">Conservatories</option>
                        <option value="61">Damp Proofing</option>
                        <option value="23">Domestic Appliance Repair</option>
                        <option value="24">Double Glazing</option>
                        <option value="25">Drains</option>
                        <option value="62">Driveways</option>
                        <option value="26">Electricians</option>
                        <option value="49">Estate Agents</option>
                        <option value="27">Exhausts</option>
                        <option value="63">Fascias, Soffits &amp; Guttering</option>
                        <option value="28">Fencing</option>
                        <option value="50">Flooring</option>
                        <option value="29">Garage Doors</option>
                        <option value="30">Garage Services</option>
                        <option value="33">Gardeners &amp; Landscapers</option>
                        <option value="31">Gas Engineers</option>
                        <option value="32">Guttering</option>
                        <option value="65">Handyman</option>
                        <option value="54">Health &amp; Beauty</option>
                        <option value="57">Hearing Aids</option>
                        <option value="34">Kitchens</option>
                        <option value="35">Locksmiths</option>
                        <option value="36">M.O.T</option>
                        <option value="56">Mobility</option>
                        <option value="55">Optitions</option>
                        <option value="37">Painters and Decorators</option>
                        <option value="38">Paving Contractors</option>
                        <option value="39">Pest Control</option>
                        <option value="40">Plasterers</option>
                        <option value="41">Plumbers</option>
                        <option value="42">Removals and Storage</option>
                        <option value="43">Roofing</option>
                        <option value="64">Sheds</option>
                        <option value="44">Skip Hire</option>
                        <option value="66">Tiling</option>
                        <option value="45">Tree Services</option>
                        <option value="46">Tyres and Exhausts</option>
                        <option value="47">Vets</option>
                        <option value="53">Website Design</option>
                        <option value="48">Wills &amp; Probate</option>
                        <option value="60">Windows</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>
                    <p>
                        <input type="submit" name="submit" value="GET MY DISCOUNT" class="standard-button"></p>
                </td>
            </tr>
        </tbody>
    </table>
</form>

和php代码:

<?php

include('mysql.php');
include('template/header.php');

$city = str_replace('-', ' ', $_GET['city']);

$result = $sql->sql_query("SELECT * FROM city WHERE city LIKE '%".$city."%' LIMIT 1");
$row = $sql->sql_fetch($result);

$code = explode('--', $_GET['code']);
$result2 = $sql->sql_query("SELECT * FROM postcode WHERE code = '".$code[0]."' LIMIT 1");
$row2 = $sql->sql_fetch($result2);

if(isset($row['id'])){
?>
<p class="abc1" style="font-family:'Arial';">Services in <?php echo     $row2['name']; ?>, <?php echo $row['city']; ?></p>
<ul class="list-unstyled">
<?php
$result3 = $sql->sql_query("SELECT * FROM pages WHERE city_id = '".$row['id']."' AND postcode = '".$row2['id']."'");
while($row3 = $sql->sql_fetch($result3)){

    $result4 = $sql->sql_query("SELECT * FROM cats WHERE id =     '".$row3['cat_id']."' LIMIT 1");
$row4 = $sql->sql_fetch($result4);

$one = str_replace(' ', '-', $row['city']);
$two = str_replace(' ', '-', $row2['name']);
$three = str_replace(' ', '-', $row4['name']);
$url = strtolower($one).'/'.$row2['code'].'--'.strtolower($two).'/'.strtolower($three).'/';
echo '<li class="list-link"><a href="http://www.450s.co/'.$url.'">'.$row4['name'].' in '.$row2['name'].', '.$row['city'].'</A></li>';
}
?>

1 个答案:

答案 0 :(得分:0)

您的表单操作说:

<form method="post" action="http://www.450s.co/index.php">

但您的PHP正在寻找$_GET['city']

您可能需要更改这样的表单方法:

<form method="get" action="http://www.450s.co/index.php">

或者您需要在$_GET上进行搜索和替换,并在PHP页面中将其替换为$_POST