Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 尽管通过表单发布了数据,但仍会将空行插入数据库_Php_Mysql_Forms_Mysqli - Fatal编程技术网

Php 尽管通过表单发布了数据,但仍会将空行插入数据库

Php 尽管通过表单发布了数据,但仍会将空行插入数据库,php,mysql,forms,mysqli,Php,Mysql,Forms,Mysqli,我用[post]方法和一个外部动作php页面制作了一个简单的HTML表单。我面临的问题是,每次按下submit按钮时,都会在数据库中插入一个空行,而不是我的输入数据 这是我的索引页: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.

我用[post]方法和一个外部动作php页面制作了一个简单的HTML表单。我面临的问题是,每次按下submit按钮时,都会在数据库中插入一个空行,而不是我的输入数据

这是我的索引页:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Webediah Add new hosting customer</title>
<style type="text/css">
.auto-style1 {
    text-align: left;
}
.auto-style2 {
    text-align: center;
}
</style>
</head>

<body>
<form id="form1" name="form1" method="post" action="add.php">
  <p>&nbsp;</p>
  <h1 class="auto-style2"><strong>New Hosting Customer </strong></h1>
  <p>&nbsp;</p>
  <table width="43%" border="0" align="center">
    <tr>
      <td width="36%" scope="row" class="auto-style1">Customer name :</td>
      <td width="64%"><label for="cname"></label>
      <input type="text" name="cname" id="cname" style="width: 233px" /></td>
    </tr>
    <tr>
      <td scope="row" class="auto-style1">Customer Domain :</td>
      <td><label for="cdomain"></label>
      <input type="text" name="cdomain" id="cdomain" style="width: 234px" /></td>
    </tr>
    <tr>
      <td scope="row" class="auto-style1">Host start on :</td>
      <td><label for="hstart"></label>
      <input type="text" name="sdate" id="hstart" style="width: 236px" /></td>
    </tr>
    <tr>
      <td scope="row" class="auto-style1">Host ends on :</td>
      <td><label for="hends"></label>
      <input type="text" name="edate" id="hends" style="width: 236px" /></td>
    </tr>
    <tr>
      <td scope="row" class="auto-style1">Customer Email :</td>
      <td><label for="cemail"></label>
      <input type="text" name="cemail" id="cemail" style="width: 237px" /></td>
    </tr>
    <tr>
      <th scope="row">&nbsp;</th>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <th scope="row"><input type="submit" name="Submit" id="Submit" value="Submit" /></th>
      <td>&nbsp;</td>
    </tr>
  </table>
  <p>&nbsp;</p>
</form>


</body>
</html>

Webediah添加新的托管客户
.auto-style1{
文本对齐:左对齐;
}
.auto-style2{
文本对齐:居中;
}

新托管客户

客户名称: 客户域: 主机启动时间: 主机结束日期: 客户电子邮件:

这是我的外部操作php页面:

<?php $con = mysqli_connect("localhost","root","111","awamah");


if (mysqli_connect_errno())
echo " error in mysql connection" . mysqli_connect_errno(); 


$sql = "INSERT INTO `customer` (`cname`,`cdomain`,`sdate`,`edate`,`cemail`) VALUES ('$_post[cname]','$_post[cdomain]','$_post[sdate]','$_post[edate]','$_post[cemail]')";

if(!mysqli_query($con,$sql))
{
    die('Error: ' . mysqli_error($con));
}
echo "1 record added";

?>
$\u POST
是一个字母,必须大写

在值查询中有
$\u post
,将它们全部更改为
$\u post
,这是主要的解释

这些也是超球体:

  • $GLOBALS
  • $\u服务器
  • 美元
  • 美元邮政
  • $\u文件
  • 美元饼干
  • 美元会议
  • $\请求
  • $\环境
要了解有关superglobals的更多信息,请访问PHP.net网站:


警告


您当前的代码对用户开放。使用,或

$\u POST而不是$\u POST。另外,您也非常容易受到SQL注入攻击。参考资料:“变量名区分大小写。”谢谢,:)我是php和mysql的初学者,所以我没有注意到这一点……是的,您没有接受第一个正确答案,相反,你接受了最后一个答案,这是第一个正确答案的明显副本。@JBES不是真的,我的朋友,我接受了最有价值的答案:)我的答案的另一个副本?弗雷德-ii-。你真丢脸。:)事实上,这是我“写”的@带解释的JBES。你写的是区分大小写的;这是一个超全球现象,这是主要原因;读一下。没有人提供实际原因。区分大小写与此有关,但不是全部。太大了;我不在乎那些该死的分数,只是为了得到正确的信息。@JBES我很少“匙食”OP。给他们一个答案,让他们自己输入,这样他们就不会犯同样的错误两次;-)另外,如果你只是为了这点而参与进来,那么你是出于错误的原因。他/她甚至不知道什么是超全球,当然也不会在意。为OP扩展一个带有无用信息的答案是没有帮助的。我来这里不是为了积分,我不想发帖了,更不用说访问了。我没过多久就意识到,这只会给网络带来问题和安全问题。互联网在你眼前的亵渎。它也被那些甚至不花时间阅读他们正在主持的内容的人所主持。完全是个骗子,愚弄训练有素的专业人士。谢谢你的评论和回答,@JBES我读了最有价值的答案并接受了它,还有一件事我必须提到的是,专业程序员在过去基本上是个初学者,他的错误使他在未来成为专业人士,,所以请不要用否定句:(