2

我是 php 新手。我在 php 中创建了一个页面,其中包含 chk 框、输入字段并从数据库(mysql)中检索数据并使用 javascript。我有一个问题,那就是我想在同一页面中显示输出。

我创建了这样的代码,我希望在同一页面中输出,但它显示错误。

<?php
if(isset($_POST['submit']))
{
  $con=mysql_connect("localhost","demosdef_review","review123");
if(!$con)
{
    die('could nt connect 2 the server');
}
mysql_select_db("demosdef_review", $con);
$state = $_POST["state"];
$country = $_POST['country'];

$contry = "USA";

if($country==1)
{
$result = mysql_query("SELECT address FROM storelocator WHERE countryid='1' AND id='$state'");
$row = mysql_fetch_array($result);
  echo $row['address'];
}
else
{
$result = mysql_query("SELECT address FROM storelocator WHERE countryid='$country'");
$row = mysql_fetch_array($result);
  echo $row['address'];
}

}
?>

    enter code here

        <div class=buy>
        <a href="dealer.php">Dealer Enquiry</a>
        </div><br/> 
        <div class=buyfont>Authorized Retailers</div>
        <div><a href="http://www.archiversonline.com/stores"><img src="images/archivers.png"><br/></a>
        <a href="http://www.archiversannex.com/Books-And-SoftwareSoftware-And-Accessoriesdefault.aspx?PageID=20&CategoryID=48"/>
        <img src="images/logo_archivers_annex.png" ></a><br/><br/>

    <a href="http://www.hobbylobby.com/storelocator"/><img src="images/logo_hobbylobby.png"></a><br/><br/>
    <a href="http://www.walgreens.com/storelocator/find.jsp"/><img src="images/logo_walgreens.png"></a></div><br/>
    <form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>
    <p>
                <label for="country" style="padding-right: 2px;">Country</label><select name="country" value="countryid"
                 id="countryid" 
                onchange="sub()" style="width:120px;">
                <option value="1">USA</option>
                <option value="2">CANADA</option>
                <option value="3">UK</option>
                <option value="4">AUSTRALIA</option>
                <option value="5">ITALY</option>
                 <option value="6">GUATEMALA</option>
                <option value="7">NEW ZEALAND</option></select></p>
                <p>
<label for="state" style="padding-right: 14px;">State</label>
<select id="state" name="state" value="state"  style="width:120px">
<option value="7">Alabama</option>
            <option value="8">Alaska</option>
            <option value="9">Arizona</option>
            <option value="10">Arkansas</option>
            <option value="11">California</option>
            <option value="12">Colorado</option>
            <option value="13">Connecticut</option>
            <option value="43">Florida</option>
            <option value="14">Georgia</option>
            <option value="15">Idaho</option>
            <option value="16">Illinois</option>
</select></p> <br/>
     <input class="dealer-submit" type="submit" value="Submit" onClick="buy_func()"/>
                  </form>  
     <script type="text/javascript">
        function sub()

        {
    var x=document.getElementById("countryid").selectedIndex;
    var y=document.getElementById("countryid").options;
    var z = document.forms[0].state;
    if(y[x].index==0){
    z.disabled = false;}
    else if(y[x].index>0) {
    z.disabled = true;}}
        </script> 
4

4 回答 4

1

您的 HTML 标记有错误

<a href="http://www.hobbylobby.com/storelocator"/>

它应该是

<a href="http://www.hobbylobby.com/storelocator">

也试试

<form method="POST" action="">

将操作保留为空白会将其发布到同一页面本身

并用这个替换你的提交按钮

<input class="dealer-submit" type="submit" name="submit" value="Submit" onClick="buy_func()"/>
于 2012-04-17T10:34:59.797 回答
0

Check the value of the submit button, if its set isset($_GET('submit')) then display the results

does that solve your problem?

于 2012-04-17T10:27:06.273 回答
0

submit is the type of the element, 'Submit' is the value you are looking for:

<?php
   if(isset($_POST['Submit']){

}
?> 
于 2012-04-17T10:29:37.207 回答
0

删除行尾的反斜杠:

<a href="http://www.hobbylobby.com/storelocator"/>
                                                ^
于 2012-04-17T11:03:14.210 回答