doujiu4643 2016-11-29 21:11
浏览 60
已采纳

从其他表单元素读取输入时如何解决错误?

I am using this code to input data from an HTML form to PHP URL page using variable but it's showing this error when running on an Apache server localhost:

; print $basicText; print ""; ?>

This the HTML code:

<html>
<head>
<title>Font Choices</title>
</head>
<body>
<center>
<h1>Font Choices</h1>
<h3>Demonstrates how to read HTML form elements</h3>
<form method = "post"
action = "borderMaker.php">
<h3>Text to modify</h3>
<textarea name = "basicText"
rows = "10"
cols = "40">
Four score and seven years ago our fathers brought forth on this
continent a new nation, conceived in liberty and dedicated to the
proposition that all men are created equal. Now we are engaged in a
great civil war, testing whether that nation or any nation so
conceived and so dedicated can long endure.
</textarea>
<table border = 2>
<tr>
<td><h3>Border style</h3></td>
<td colspan = 2><h3>Border Size</h3></td>
</tr>
<tr>
<td>
<select name = borderStyle>
<option value = "ridge">ridge</option>
<option value = 
"groove">groove</option>
<option value = "double">double</option>
<option value = "inset">inset</option>
<option value = "outset">outset</option>
</select>
</td>
<td>
<select size = 5
name = borderSize>
<option value = "1">1</option>
<option value = "2">2</option>
<option value = "3">3</option>
<option value = "5">5</option>
<option value = "10">10</option>
</select>
</td>
<td>
<input type = "radio"
name = "sizeType"
value = "px">pixels<br>
<input type = "radio"
name = "sizeType"
value = "pt">points<br>
<input type = "radio"
name = "sizeType"
value = "cm">centimeters<br>
<input type = "radio"
name = "sizeType"
value = "in">inches<br>
</td>
</tr>
</table>
<input type = "submit"
value = "show me">
</form>
</center>
</body>
</html>

And this code of PHP page:

<html>
<head>
<title>Your Output</title>
</head>
<body>
<h1>Your Output</h1>
<center>
<?

$theStyle = <<<HERE
"border-width:$borderSize,$sizeType;
border-style:$borderStyle;
border-color:green"
HERE;
print "<div style = $theStyle>";
print  '$basicText'; 
print "</span>";

?>
    </div>
</center>
</body>
</html>
  • 写回答

2条回答 默认 最新

  • dongwen9947 2016-11-29 21:37
    关注

    Try to modify your PHP page like below:

    <?php extract($_POST); ?>
    <html>
    <head>
    <title>Your Output</title>
    </head>
    <body>
    <h1>Your Output</h1>
    <center>
        <div style ="border-width:<?= $borderSize.','.$sizeType;?>;border-style:<?= $borderStyle;?>;border-color:green">
            <?= $basicText;?></span>";
        </div>
    </center>
    </body>
    </html>
    

    On the above code extract converts all your post data into variables. This works as you have used the same name for your variables (in your php code) and form inputs (in the html file). However, you could also replace extract by simply assigning your post vars to individual variables.

    $borderSize = $_POST['borderSize'];
    $sizeType = $_POST['sizeType'];
    $borderStyle = $_POST['borderStyle'];
    $basicText = $_POST['basicText'];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP