2016-09-12 129 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); 
?>