doushan5222 2017-04-05 19:09
浏览 30
已采纳

即使表单中的字段,PHP表单也会返回错误

PHP code:

<html>
<head>
<head>
</head>
<body bgcolor="000033" text="navy">
<?php
$nume="";
$email="";
$subiect="";
if (!$nume || !$email || !$subiect)
{
?>
<h4 style="color:gray" align="center">
Eroare: Toate campurile sunt obligatorii!</h4>
<p align="center">
Corectati <a href="javascript:history.go(-1)">formularul</a>
</p>
<?
}
else{
?>
<h4 style="color: green;" align="center">
Formularul introdus </h4>
<hr size="1" width="75%">
<?
$mesaj = "";
$mesaj .= "<impresie data=\"". date("d M Y, G:i");
$mesaj .= "\" client = \"" . $REMOTE_HOST . "(" . $REMOTE_ADDR . ")\">
";
$mesaj .= "<nume email=\"" . $email . "\">" . $nume . "</nume>
";
if ($subiect)
$mesaj .= "<text>
" . $subiect . "
</text>
</subiect>
";
mail("sitecurs18@gmail.com", "subiect", $mesaj, "from:". $email);
}
?>
<hr size="1" width="75%">
</body>
</html>

Form code:

<html>
<head>
<title>Contact</title>
<style type="text/css">
body {background-color: 000033;
}
table {margin-top: 10px;}
</style>
</head>
<body>
<form action="prelucrare.php">
<table width="800" align="center" rows="5" cols="3" cellspacing="0" border="0">
<tr>
<td bgcolor="gray" colspan="3"><font face="serif" color="000033" size="+3">Contact</font></td>
</tr>
<tr>
<td width="175" height="65" align="left" valign="center"><font face="arial" color="gray"size="3"><p>Numele &#351;i prenumele:</p></font></td>
<td width="225" align="left" valign="center"><input name="nume" type="text" value=""></td>
</tr>
<tr>
<td height="65"><font face="arial" color="gray" size="3"><p>Adresa e-mail:</p></font></td>
<td><input name="email" type="text" value=""></td>
</tr>
<tr>
<td height="65"><font face="arial" color="gray" size="3"><p>Subiect:</p></font></td>
<td><textarea rows="6" cols="40" name="subiect"></textarea></td>
</tr>
<tr>
<td height="65" align="right"><input type="submit" value="Trimite"></td>
<td align="center"><input type="reset" value="&#350;terge"></td>
</tr>
</table>
</form>
</body>
</html>

When i submit the form it takes me straight to the error page saying I didn't fill in all the fields,I tried everything but couldn't fix it.

I've tried defining the variables for the fields as empty,but it changed nothing,and also tried changing the php tags from

  • 写回答

1条回答 默认 最新

  • dongzai3139 2017-04-05 19:21
    关注

    You need to read form variable and assign them to your php variable. You have not mentioned method type i.e get or post. By default it is get so use get to read form values like this:

    $nume = $_GET["nume"];
    $email = $_GET["email"];
    $subiect = $_GET["subiect"];
    

    If you want post mention method=post in your form & replace get with post to read values.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?