2016-09-12 59 views
0

所以,即時通訊試圖獲得信息,你把一個HTML到一個表中的PHP,問題是,我無法找到任何解決方案在線。並且我對php還不太瞭解。這只是我第二次問一些問題,所以我還是不太清楚你應該填寫問題的方式。總之,這裏是有問題的代碼:Html表格到Php表

HTML

</head> 
<body> 
<form action="http://www.cs.tut.fi/cgi-bin/run~jkorpela/echo.cgi"method="post"> 
<div> 
<label for="vnaam">Voornaam</label> 
<input type="text" id="vnaam" name="vnaam" required/> 
</div> 
<div> 
<label for="anaam">Achternaam</label> 
<input type="text" id="anaam" name="anaam" required/> 
</div> 
<div> 
<label for="tnum">Telefoon Nummer</label> 
<input type="text" id="tnum" name="tnum" /> 
</div> 
<div> 
<label for="tnum">E-mail</label> 
<input type="email" id="tnum" name="tnum" /> 
</div> 
<div> 
<label for="adres">Adres</label> 
<input type="" id="adres" name="adres" required/> 
</div> 
<div> 

<label for="land">Land</label> 
<select id="land" name="land"> 
    <option value="ned">Nederland</option> 
    <option value="usa">Amerika</option> 
    <option value="eng">Engeland</option> 
    <option value="bel">België</option> 
    <option value="fr">Frankrijk</option> 
    <option value="ger">Duitsland</option> 
</select> 
</div> 
<div class="button"> 
<button type="submit">Opsturen</button> 

</div> 
</form> 



</body> 
</html> 

的CSS

<style type="text/css"> 
form { 
/* Just to center the form on the page */ 
margin: 0 auto; 
width: 400px; 
/* To see the outline of the form */ 
padding: 1em; 
border: 1px solid #CCC; 
border-radius: 1em; 
} 
form div + div { 
margin-top: 1em; 
} 
label { 
    /* To make sure that all labels have the same size and are properly  aligned */ 
    display: inline-block; 
width: 90px; 
text-align: right; 
} 
input, textarea { 
/* To make sure that all text fields have the same font settings 
    By default, textareas have a monospace font */ 
font: 1em sans-serif; 

/* To give the same size to all text field */ 
width: 300px; 
-moz-box-sizing: border-box; 
box-sizing: border-box; 

/* To harmonize the look & feel of text field border */ 
border: 1px solid #999; 
} 
input:focus, textarea:focus { 
/* To give a little highlight on active elements */ 
border-color: #000; 
} 
textarea { 
/* To properly align multiline text fields with their labels */ 
vertical-align: top; 

/* To give enough room to type some text */ 
height: 5em; 

/* To allow users to resize any textarea vertically 
    It does not work on all browsers */ 
resize: vertical; 
} 
.button { 
/* To position the buttons to the same position of the text fields */ 
padding-left: 90px; /* same size as the label elements */ 
} 
button { 
/* This extra margin represent roughly the same space as the space 
    between the labels and their text fields */ 
margin-left: .5em; 
} 

</style> 
+0

既然你剛剛開始學習PHP,那麼做對 - 完全避免mysql_'的擴展!您可以使用'mysqli_'(注意末尾的'i')或PDO。請務必使用帶有佔位符的準備好的語句來保護您的數據庫。查看下面的例子:http://php.net/manual/en/mysqli.prepare.php或者你想嘗試PDO http://php.net/manual/en/pdo.prepare.php - CSS也與此問題無關,因爲CSS與頁面的外觀/樣式有關,而PHP是後端語言,根本不在乎它的外觀;-) – Qirel

+0

閱讀關於php表單處理 http: //www.w3schools.com/php/php_forms.asp –

+0

有很多關於PHP處理表單的教程。仔細閱讀一些內容,然後花時間去真正理解。然後自己嘗試一下。之後,如果您仍然遇到問題,請發佈您正在使用的PHP代碼,描述所需的行爲,並描述實際行爲,包括任何錯誤。 –

回答

0
<form method='POST' action='formhandler.php'> 
    <input type='text' name='name' value='john'> 
    <input type='text' name='address' value='32 flowers street'> 
    <input type='text' name='email' value='[email protected]'> 
</form> 

這樣一個典型的形式將被瀏覽器傳遞到PHP文件formhandler.php

然後你處理它在你的formhandler.php文件

formhandler.php

$name = isset($_POST['name']) ? $_POST['name'] : ""; 
$address= isset($_POST['address']) ? $_POST['address'] : ""; 
$email= isset($_POST['email']) ? $_POST['email'] : ""; 
echo $name; //john 
echo $address; //32 flowers street 
echo $email; //[email protected] 

現在你有表格數據。根據需要使用它,將它們存儲在數據庫中,爲用戶構建另一個html響應文件,或者做任何你想做的事情。例如,我們要將數據反饋給用戶。

echo "We have successfully received your inputs as <br> 
<table> 
    <tbody> 
     <tr><td>name</td><td>$name</td></tr> 
     <tr><td>address</td><td>$address</td></tr> 
     <tr><td>email</td><td>$email</td></tr> 
    </tbody> 
</table>"; 

注:在現實生活生產需要validate任何輸入來你的PHP文件第一。

0

首先改變 <form action="http://www.cs.tut.fi/cgi-bin/run~jkorpela/echo.cgi"method="post">

喜歡的東西

<form action="http://www.cs.tut.fi/getdata.php" method="post"> 

因爲您使用的是cgi-bin/run~jkorpela/echo.cgi,它不用於獲取php數據,因爲它的文件爲cgi。應該在服務器上安裝.php擴展文件和php。我假設http://www.cs.tut.fi/是您的網站的網址。

其中getdata.php是您獲取所有輸入值的php文件。您需要在您的服務器上創建該文件。如果你是AWS那麼它可能是這樣的/var/www/html/

訪問getdata.php

<?php 
    echo "<pre>"; 
    print_r($_REQUEST); 
?>