duanhuanzhi6431 2015-08-30 06:10
浏览 58

文本框中的名称不是来自php的回显

The code:

<!DOCTYPE html>
<html>
<head>
<title>Greeting Service!</title>
</head>
<body>
<center>
<form method="post" action="">
<h1>What's Your Name?</h1>
<input type="text" name="name" placeholder="Name Here" />
<h4>Greet me in:
<select name="language">
<option value="option1">English</option>
<option value="option2">Chinese</option>
<option value="option3">French</option>
</select>
</h4>
<input type="submit" value="Greet Me!" />
<?php
if (isset($_POST['language'])) {
switch ($language) {
case "option1":
$result = "Hello, $name!"; 
break;
case "option2":
$result = "你好, $name!"; 
break;
case "option3":
$result = "Bonjour, $name!"; 
break;
}
}
?>
</form>
</center>
</body>
</html>

I'm not sure why it doesn't display the name i enter in from the input text box with the greeting according to each different language. I have used $_POST to submit the form and used a switch and case in my php code. Can someone help me out, i would like the name that is entered in the textbox to display when i have chosen which language i want the greeting to come out with. Thanks.

  • 写回答

5条回答 默认 最新

  • du1108 2015-08-30 06:12
    关注

    You don't have $language defined. What you should use is $_POST['language'] :

    if (isset($_POST['language'])) {
    switch ($_POST['language']) {
    

    EDIT: didn't notice the $name variable as said by Meenesh Jain. And the last thing: you never do anything with the result. Not sure if that's intended or not, but I would add an echo $result; at the end.

    评论

报告相同问题?

悬赏问题

  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)