2012-04-17 70 views
2

即時通訊新的php.i創建一個頁面在PHP中包含chk框,輸入字段和從數據庫中檢索數據(mysql),並使用javascript。 我在這方面有一個問題,那就是我想在同一頁面顯示輸出。在同一頁面顯示輸出使用php

我創建了這樣的代碼,我想輸出在同一頁,但它顯示錯誤。

<?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> 
+0

這是一個正確的副本嗎?因爲你錯過了一個關閉「在窗體的行動 – 2012-04-17 10:34:42

回答

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()"/> 
+0

謝謝,它的工作 – leela 2012-04-17 10:59:07

+0

高興地幫助。你能請我嗎? – asprin 2012-04-17 11:04:12

0

檢查提交按鈕的值,如果將其設置isset($_GET('submit'))然後顯示結果

這是否解決問題了嗎?

0

提交是元素的類型, '提交' 是您正在尋找的價值:

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

} 
?> 
0

提交按鈕在該行的末尾刪除反斜槓:

<a href="http://www.hobbylobby.com/storelocator"/> 
               ^
相關問題