
正文
php发送表单数据格式 php发送表单数据格式怎么写
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
求救!表单通过php提交数据到mysql中文乱码
1、页面代码里面要设置charset=utf-8
2、保存页面文件时要编码格式为utf-8
3、数据库有关php发送表单数据格式的表、字段、的编码为utf8-general-ci
还不对的话php发送表单数据格式,看下面。
我是这样解决的:
$dbh = new PDO('mysql:host=localhost;dbname=test','root','');
$dbh-exec("SET NAMES 'utf8';");
或者没用PDO
mysql_query("set names 'utf-8'");
相关问答
Q1: PHP表单格式定义
1、PHP程序判断
需要在提交内容php发送表单数据格式的时候php发送表单数据格式,在php程序中先判断(正则等),然后返回错误消息
比如:
if(!$_post[name]){
echo
"姓名不能为空!";
}
缺点:会有跳转页面,对用户不友好
2、js(jquery框架比较简单)之类的
推荐Jquery.validate插件,使用很简单,不用跳转页面,填的时候就可以判断输入是否正确并给出提示消息(可以自定义),如:
先引用引入jquery.js
$(document).ready(function(){
$("#myform").validate({
//#myform是指form
id="myform",jquery选择一个表单
rules:
{
userName:
{
//userName这个input必须要填,可以随意写很多个
required:
true,
//加这个,证明必须要填对
byteRangeLength:
[3,15]
//一些自定义的判断规则
},
email:
{
required:
true,
email:
true
//必须是邮件格式,已经预先定义好的规则
}
},
messages:
{
userName:
{
required:
"请填写用户名",
byteRangeLength:
"用户名必须在3-15个字符之间(一个中文字算2个字符)"
},
email:
{
required:
"请填写密码",
email:
"email格式不对"
//对应的规则,对应的input要写对应的提示语句
}
}
});
3、Ajax验证,可以在当前页面验证,比上面强大的是,还可以验证在数据库中是不是已经存在,但是要懂ajax和程序交互
推荐2,开发难度和用户体验都比较好。
Q2: 表单提交有那两种方式?PHP如何获得表单提交的数据?
1. 修改php.iniphp发送表单数据格式,查找 register_globals,将其值修改为 On。这样就可以像原来一样,例如,提交的表单中包括一个名为"username"的变量,那么在php中就可以直接使用$username来访问该变量。但是,除非php发送表单数据格式你要使用一段旧的代码而考虑到兼容性问题,否则不建议使用该方法。
2. 使用 $HTTP_GET_VARS、$HTTP_POST_VARS数组来访问,例如写成$HTTP_POST_VARS["username"]的形式。不过该方法也不建议采用。
3. (推荐)使用 $_POST、$_GET等数组来访问,例如写成 $_POST["username"]的形式。建议采用这种方法。
(推荐)使用 import_request_variables 函数。该函数将提交内容导入到变量中。
例如 import_request_variables("gp", "rvar_");第一个参数可以选择g,p,c,分别表示导入 GET,POST,COOKIE 变量;第二个参数为导入后的变量前缀。执行上面的语句后即可使用 $rvar_username 来访问提交的 username 变量。使用import_request_variables("gp", "");可以兼容以前的PHP程序。
PHP $_GET 和 $_POST变量是用来获取表单中的信息的,比如用户输入的信息。
PHP表单操作
在php发送表单数据格式我们处理HTML表单和PHP表单时,php发送表单数据格式我们要记住的重要一点是:HTML页面中的任何一个表单元素都可以自动的用于PHP脚本:
Q3: form表单的字符串 怎么使用 php
PHP 表单处理
PHP 超全局
PHP 表单验证
PHP 超全局变量 $_GET 和 $_POST 用于收集表单数据(form-data)。
PHP - 一个简单php发送表单数据格式的 HTML 表单
下面的例子显示了一个简单的 HTML 表单php发送表单数据格式,它包含两个输入字段和一个提交按钮:
实例
html
body
form action="welcome.php" method="post"
Name: input type="text" name="name"br
E-mail: input type="text" name="email"br
input type="submit"
/form
/body
/html
运行实例
当用户填写此表单并点击提交按钮后php发送表单数据格式,表单数据会发送到名为 "welcome.php" 的 PHP 文件供处理。表单数据是通过 HTTP POST 方法发送的。
如需显示出被提交的数据,您可以简单地输出(echo)所有变量。"welcome.php" 文件是这样的:
html
body
Welcome ?php echo $_POST["name"]; ?br
Your email address is: ?php echo $_POST["email"]; ?
/body
/html
输出:
Welcome John
Your email address is john.doe@example.com
使用 HTTP GET 方法也能得到相同的结果:
实例
html
body
form action="welcome_get.php" method="get"
Name: input type="text" name="name"br
E-mail: input type="text" name="email"br
input type="submit"
/form
/body
/html
运行实例
"welcome_get.php" 是这样的:
html
body
Welcome ?php echo $_GET["name"]; ?br
Your email address is: ?php echo $_GET["email"]; ?
/body
/html
上面的代码很简单。不过,最重要的内容被漏掉了。您需要对表单数据进行验证,以防止脚本出现漏洞。
注意:在处理 PHP 表单时请关注安全php发送表单数据格式!
本页未包含任何表单验证程序,它只向php发送表单数据格式我们展示如何发送并接收表单数据。
不过稍后的章节会为您讲解如何提高 PHP 表单的安全性!对表单适当的安全验证对于抵御黑客攻击和垃圾邮件非常重要!
GET vs. POST
GET 和 POST 都创建数组(例如,array( key = value, key2 = value2, key3 = value3, ...))。此数组包含键/值对,其中的键是表单控件的名称,而值是来自用户的输入数据。
GET 和 POST 被视作 $_GET 和 $_POST。它们是超全局变量,这意味着对它们的访问无需考虑作用域 - 无需任何特殊代码,您能够从任何函数、类或文件访问它们。
$_GET 是通过 URL 参数传递到当前脚本的变量数组。
$_POST 是通过 HTTP POST 传递到当前脚本的变量数组。
何时使用 GET?
通过 GET 方法从表单发送的信息对任何人都是可见的(所有变量名和值都显示在 URL 中)。GET 对所发送信息的数量也有限制。限制在大于 2000 个字符。不过,由于变量显示在 URL 中,把页面添加到书签中也更为方便。
GET 可用于发送非敏感的数据。
注释:绝不能使用 GET 来发送密码或其他敏感信息!
何时使用 POST?
通过 POST 方法从表单发送的信息对其他人是不可见的(所有名称/值会被嵌入 HTTP 请求的主体中),并且对所发送信息的数量也无限制。
此外 POST 支持高阶功能,比如在向服务器上传文件时进行 multi-part 二进制输入。
不过,由于变量未显示在 URL 中,也就无法将页面添加到书签。
Q4: 新手想做一个PHP的表单提交发送到指定邮箱,请高手指教?
首先包含一个邮件发送类 require("sendMail.php");
然后你要有一个发送邮件的服务器(可以到163随意注册个,例如注册的是aa@163.com,密码是aa123),然后是发送邮件的代码,我给你一个我用的例子
$smtpserver = "smtp.163.com"; //你选择的SMTP服务器
$smtpserverport =25; //SMTP服务器端口
$smtpusermail = "aa@163.com"; //SMTP服务器的用户邮箱
$smtpemailto = "bb@qq.com"; //收件箱
$smtpuser = "aa@163.com"; //SMTP服务器的用户帐号
$smtppass = "aa123"; //SMTP服务器的用户密码
$MailBody="姓名:".$_POST['Name'];//邮件内容(如你提交的表单姓名为Name)
$mailsubject=@iconv("UTF-8", "gb2312", "XX网站-问题提交");//如果你页面为UTF-8,这里还要转码一下
$mailbody = $MailBody; //邮件内容
$mailtype = "HTML"; //邮件格式(HTML/TXT),TXT为文本邮件
$smtp = new smtp($smtpserver,$smtpserverport,true,$smtpuser,$smtppass);//true表示使用身份验证,否则不使用身份验证.
$smtp-debug = FALSE; //是否显示发送的调试信息 TRUE发送 FALSE不发送
$smtp-sendmail($smtpemailto, $smtpusermail, $mailsubject, $mailbody, $mailtype);
sendMail.php代码:
class smtp
{
/* Public Variables */
var $smtp_port; //邮件服务器端口
var $time_out; //超时时间
var $host_name; //主机名称
var $log_file; //日志文件
var $relay_host; //
var $debug;
var $auth;
var $user; //用户名
var $pass; //密码
var $sock;
/* Constractor */
function smtp($relay_host, $smtp_port,$auth,$user,$pass)
{
// echo $relay_host." ".$smtp_port." ".$auth." ".$user." ".$pass;
$this-debug = FALSE;
$this-smtp_port = $smtp_port;
$this-relay_host = $relay_host;
$this-time_out = 30;//is used in fsockopen()
$this-auth = $auth;//auth
$this-user = $user;
$this-pass = $pass;
$this-host_name = "localhost";//is used in HELO command
$this-log_file = "";
$this-sock = FALSE;
}
/* Main Function */
function sendmail($to, $from, $subject = "", $body = "", $mailtype, $cc = "", $bcc = "", $additional_headers = "")
{
$mail_from = $this-get_address($this-strip_comment($from));
$body = ereg_replace("(^|(\r\n))(\.)", "\1.\3", $body);
$header .= "MIME-Version:1.0\r\n";
if($mailtype=="HTML"){
$header .= "Content-Type:text/html\r\n";
}
$header .= "To: ".$to."\r\n";
if ($cc != "") {
$header .= "Cc: ".$cc."\r\n";
}
$header .= "From: $from".$from."\r\n";
$header .= "Subject: ".$subject."\r\n";
$header .= $additional_headers;
$header .= "Date: ".date("r")."\r\n";
$header .= "X-Mailer:By Redhat (PHP/".phpversion().")\r\n";
list($msec, $sec) = explode(" ", microtime());
$header .= "Message-ID: ".date("YmdHis", $sec).".".($msec*1000000).".".$mail_from."\r\n";
$TO = explode(",", $this-strip_comment($to));
if ($cc != "") {
$TO = array_merge($TO, explode(",", $this-strip_comment($cc)));
}
if ($bcc != "") {
$TO = array_merge($TO, explode(",", $this-strip_comment($bcc)));
}
$sent = TRUE;
foreach ($TO as $rcpt_to) {
$rcpt_to = $this-get_address($rcpt_to);
if (!$this-smtp_sockopen($rcpt_to)) {
$this-log_write("Error: Cannot send email to ".$rcpt_to."\n");
$sent = FALSE;
continue;
}
if ($this-smtp_send($this-host_name, $mail_from, $rcpt_to, $header, $body)) {
$this-log_write("E-mail has been sent to ".$rcpt_to."\n");
}
else {
$this-log_write("Error: Cannot send email to ".$rcpt_to."\n");
$sent = FALSE;
}
fclose($this-sock);
$this-log_write("Disconnected from remote host\n");
}
return $sent;
}
/* Private Functions */
function smtp_send($helo, $from, $to, $header, $body = "")
{
if (!$this-smtp_putcmd("HELO", $helo)) {
return $this-smtp_error("sending HELO command");
}
if($this-auth){
if (!$this-smtp_putcmd("AUTH LOGIN", base64_encode($this-user))) {
return $this-smtp_error("sending HELO command");
}
if (!$this-smtp_putcmd("", base64_encode($this-pass))) {
return $this-smtp_error("sending HELO command");
}
}
if (!$this-smtp_putcmd("MAIL", "FROM:".$from."")) {
return $this-smtp_error("sending MAIL FROM command");
}
if (!$this-smtp_putcmd("RCPT", "TO:".$to."")) {
return $this-smtp_error("sending RCPT TO command");
}
if (!$this-smtp_putcmd("DATA")) {
return $this-smtp_error("sending DATA command");
}
if (!$this-smtp_message($header, $body)) {
return $this-smtp_error("sending message");
}
if (!$this-smtp_eom()) {
return $this-smtp_error("sending CRLF.CRLF [EOM]");
}
if (!$this-smtp_putcmd("QUIT")) {
return $this-smtp_error("sending QUIT command");
}
return TRUE;
}
function smtp_sockopen($address)
{
if ($this-relay_host == "") {
return $this-smtp_sockopen_mx($address);
} else {
return $this-smtp_sockopen_relay();
}
}
function smtp_sockopen_relay()
{
$this-log_write("Trying to ".$this-relay_host.":".$this-smtp_port."\n");
$this-sock = @fsockopen($this-relay_host, $this-smtp_port, $errno, $errstr, $this-time_out);
if (!($this-sock $this-smtp_ok())) {
$this-log_write("Error: Cannot connenct to relay host ".$this-relay_host."\n");
$this-log_write("Error: ".$errstr." (".$errno.")\n");
return FALSE;
}
$this-log_write("Connected to relay host ".$this-relay_host."\n");
return TRUE;
}
function smtp_sockopen_mx($address)
{
$domain = ereg_replace("^.+@([^@]+)$", "\1", $address);
if (!@getmxrr($domain, $MXHOSTS)) {
$this-log_write("Error: Cannot resolve MX \"".$domain."\"\n");
return FALSE;
}
foreach ($MXHOSTS as $host) {
$this-log_write("Trying to ".$host.":".$this-smtp_port."\n");
$this-sock = @fsockopen($host, $this-smtp_port, $errno, $errstr, $this-time_out);
if (!($this-sock $this-smtp_ok())) {
$this-log_write("Warning: Cannot connect to mx host ".$host."\n");
$this-log_write("Error: ".$errstr." (".$errno.")\n");
continue;
}
$this-log_write("Connected to mx host ".$host."\n");
return TRUE;
}
$this-log_write("Error: Cannot connect to any mx hosts (".implode(", ", $MXHOSTS).")\n");
return FALSE;
}
function smtp_message($header, $body)
{
fputs($this-sock, $header."\r\n".$body);
$this-smtp_debug(" ".str_replace("\r\n", "\n"." ", $header."\n ".$body."\n "));
return TRUE;
}
function smtp_eom()
{
fputs($this-sock, "\r\n.\r\n");
$this-smtp_debug(". [EOM]\n");
return $this-smtp_ok();
}
function smtp_ok()
{
$response = str_replace("\r\n", "", fgets($this-sock, 512));
$this-smtp_debug($response."\n");
if (!ereg("^[23]", $response)) {
fputs($this-sock, "QUIT\r\n");
fgets($this-sock, 512);
$this-log_write("Error: Remote host returned \"".$response."\"\n");
return FALSE;
}
return TRUE;
}
function smtp_putcmd($cmd, $arg = "")
{
if ($arg != "") {
if($cmd=="") $cmd = $arg;
else $cmd = $cmd." ".$arg;
}
fputs($this-sock, $cmd."\r\n");
$this-smtp_debug(" ".$cmd."\n");
return $this-smtp_ok();
}
function smtp_error($string)
{
$this-log_write("Error: Error occurred while ".$string.".\n");
return FALSE;
}
function log_write($message)
{
$this-smtp_debug($message);
if ($this-log_file == "") {
return TRUE;
}
$message = date("M d H:i:s ").get_current_user()."[".getmypid()."]: ".$message;
if (!@file_exists($this-log_file) || !($fp = @fopen($this-log_file, "a"))) {
$this-smtp_debug("Warning: Cannot open log file \"".$this-log_file."\"\n");
return FALSE;;
}
flock($fp, LOCK_EX);
fputs($fp, $message);
fclose($fp);
return TRUE;
}
function strip_comment($address)
{
$comment = "\([^()]*\)";
while (ereg($comment, $address)) {
$address = ereg_replace($comment, "", $address);
}
return $address;
}
function get_address($address)
{
$address = ereg_replace("([ \t\r\n])+", "", $address);
$address = ereg_replace("^.*(.+).*$", "\1", $address);
return $address;
}
function smtp_debug($message)
{
if ($this-debug) {
//echo $message;
}
}
}
Q5: php表单传值问题
我认为你编写的程序正确,你的这两个语句确实能把id带到edit.php或者del.php:
[a href="edit.php?id=?php echo $row[0]; ?"编辑/a]
[a href="del.php?id=?php echo $row[0]; ?"删除/a]
鼠标点击编辑的连接,如果浏览器的地址变为这样的格式,说明你这个参数是传过去了的,本程序没有问题。问题可能出在edit.php,是不是它没有正确的去接收参数。
php发送表单数据格式的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于php发送表单数据格式怎么写、php发送表单数据格式的信息别忘了在本站进行查找喔。






