2016-11-29 44 views
1

我使用變量使用此代碼的輸入數據從一個HTML表單PHP網址的頁面,但在Apache服務器本地主機上運行時,它顯示這個錯誤:如何從其他表單元素讀取輸入時解決錯誤?

; print $basicText; print ""; ?> 

此HTML代碼:

<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> 

而這種代碼PHP頁面:

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

貌似php根本不處理,查看source-> see php? – 2016-11-29 21:14:32

+0

你也必須爲你的變量賦值。 $ yorVar = $ _POST ['yourInput']; –

回答

-1

嘗試修改你的PHP頁面如下圖所示:

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

在上面的代碼extract所有職位數據轉換成變量。這是因爲你已經爲你的變量(在你的php代碼中)和表單輸入(在html文件中)使用了相同的名字。但是,您也可以通過簡單地將您的後置變量分配給各個變量來替換抽取。

$borderSize = $_POST['borderSize']; 
$sizeType = $_POST['sizeType']; 
$borderStyle = $_POST['borderStyle']; 
$basicText = $_POST['basicText']; 
+0

非常感謝這對我很有幫助...... !!!! – Almadani

+0

不客氣。我很高興我可以幫助:) –

+0

提取物是危險的,你應該真正小心推薦它 – 2016-11-29 22:27:17

0
print "<div style = {$theStyle}>"; 
print $basicText; 
print "</span>"; 

print "<div style = ".$theStyle.">"; 
print "$basicText"; 
print "</span>"; 
+0

感謝兄弟這對我很有幫助...再次感謝你 – Almadani

相關問題