我是php.i的新手在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>
答案 0 :(得分: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()"/>
答案 1 :(得分:0)
检查提交按钮的值,如果其设置为isset($_GET('submit'))
,则显示结果
这可以解决你的问题吗?
答案 2 :(得分:0)
submit是元素的类型,'Submit'是您要查找的值:
<?php
if(isset($_POST['Submit']){
}
?>
答案 3 :(得分:0)
删除行尾的反斜杠:
<a href="http://www.hobbylobby.com/storelocator"/>
^