這些PHP值在將空變量設置爲值並將其發佈到頁面後輸出空數據。有誰知道爲什麼?PHP變量在設置值後看起來爲空
這裏是我的代碼:
PHP:
<?php
$name = $_POST['query'];
$cap = null;
$ugly = "http://25.media.tumblr.com/tumblr_m3v5kj4ERf1qijcxeo1_500.gif";
$pretty = "http://upload.wikimedia.org/wikipedia/commons/e/e8/Bebe_Phoque_de_Weddell_Baby_Weddell_Seal.gif";
$hot = "http://hosting01.hotchyx.com/adult-image-hosting-42/466laugh.gif";
$weird = "http://d2tq98mqfjyz2l.cloudfront.net/image_cache/1308355337507544.gif";
$choice = null;
$little = null;
$adj1 = "walrus devouring";
$adj2 = "cat canoodling";
$adj3 = "voluptuous machine of ghettoness and stupidity";
$adjch = null;
$i = rand(1,4);
$w = rand(1,3);
if(w == 1)
{
$adjch = $adj1;
}
elseif (w == 2)
{
$adjch = $adj2;
}
elseif (w == 3)
{
$adjch = $adj3;
}
if(i == 1)
{
$choice = $ugly;
$little = "You should probably see a doctor.";
$cap = "$name, You're uglier than all of One Direction * 2 + 100. That's pretty bad.";
}
elseif (i == 2)
{
$choice = $weird;
$cap = "$name, you're weird.";
$little = "I wish I didn't know you and you didn't exist you creepy, $adjch diddly do gooder.";
}
elseif (i == 3)
{
$choice = $pretty;
$cap = "$name, you're the prettiest $adjch person on earth.";
$little = "ilu so much";
}
else if(i == 4)
{
$choice = $hot;
$cap = "$name, help the homeless. Take me home with you.";
$little = "You're hot. Really hot.";
}
?>
HTML:
<html>
<link href="css/bootstrap.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container-fluid">
<button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div class="nav-collapse collapse">
<ul class="nav">
<li class="active"><a href="index.html">Home</a></li>
<li><a href="blog.html">Blog</a></li>
<li><a href="about.html">About</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
</div>
<div class='push'></div>
<p><img src="<?php echo $choice;?>"</p>
<h2 align='center'><strong><?php echo $cap;?></strong></h2>
<p><?php echo $little;?></p>
<p><a href="index.html" class='btn'><i class="icon-search"></i> Go back </a></p>
</body>
<div class='footerpush'></div>
<hr>
<div align='center'>
<a href='about.html'>about</a>
|
<a href='blog.html'>blog</a>
|
<a href='twitter.com'>twitter</a>
|
<a href='notice.html'>our policy</a>
</div>
<p>© bleh blah</p>
</html>
謝謝大家(PS,我是一個PHP小白很抱歉)
請把這裏的編碼。 –
我剛剛格式化了您的代碼,以符合規則。快速問題:你是否用.php擴展名命名了你的html文件?你是否在服務器上運行它? –
一旦解決問題,請不要刪除您的問題。 – michaelb958