导航:首页 > 编程语言 > php表单提交代码

php表单提交代码

发布时间:2022-09-01 19:30:35

A. 由网页提交的表单提交写入数据库 php源代码该怎么写

把下面的代码保存为post.php

<?
$conn = mysql_connect("localhost","11111","22222");
$action = $_POST['action'];
if($action == 'send'){
$username = $_POST['username'];
$password = $_POST['password'];
mysql_select_db("333333",$conn);
$sql = "INSERT INTO player (username,password) VALUES ('$username','$password')";
$result = mysql_query($sql,$conn);
}
?>

<html>
<body>
<form method="post" action="post.php">
<input type="text" name="username">
<input type="text" name="password">
<input type="hidden" name="action" value="send">
<input type="submit" name="Submit" value="提交">
</form>
</body>
</html>

B. PHP怎么把表单提交到本页

PHP把表单提交到本页,这个的话,我们是通过<form action="提交的文件名">来实现的,还有一个传值的方式,post或者是get可以通过METHOD来实现的,这里我写一段代码:
<html>
<head></head>

<body>
<form action='文件名' method="post">
姓名<input type='text' value="">

密码<input type='text' value="">
email<input type='text' value="">
</form>

</body>

</html>

C. PHP 表单 提交数据到mysql

PHP 提交表单,然后保存数据库示例:

1.sql脚本:

createdatabasecompany;
usecompany;
createtableemployee(
idint(11)notnullprimarykeyauto_increment,
emp_namevarchar(20)notnull,
emp_novarchar(30)notnull,
emp_jobvarchar(50)
);

2.index.php代码:

<?php
header("Content-type:text/html;charset=utf-8;");
//判断是否提交表单
if(isset($_POST['btn'])){
//连接数据库
$conn=mysql_connect("localhost","root","root");
if(!$conn){
die("数据库连接错误!".mysql_error());
}
mysql_select_db("company");
mysql_query("setnamesutf8");
//获取表单提交元素
$emp_name=$_POST['emp_name'];
$emp_no=$_POST['emp_no'];
$emp_job=$_POST['emp_job'];
//验证表单元素,然后入库操作
if($emp_name&&$emp_no&&$emp_job){
$sql="insertintoemployee
(emp_name,emp_no,emp_job)
values
('{$emp_name}','{$emp_no}','{$emp_job}')
";
$int=mysql_query($sql);
$suc_msg="<fontcolor='green'>数据插入成功!</font><ahref='javascript:history.go(-1);'>返回</a>";
$err_msg="数据插入失败";
exit($int?$suc_msg:$err_msg);
}else{
exit("提交数据全部为必填项!");
}
}
?>
<html>
<head>
<title>PHP表单提交示例</title>
<metahttp-equiv="content-type"content="text/html;charset=utf-8"/>
</head>
<body>
<formid="myform"action="<?phpecho$_SERVER['PHP_SELF']?>"method="post">
员工姓名:<inputname="emp_name"type="text"/><br/>
工号:<inputname="emp_no"type="text"/><br/>
工作职责:<inputname="emp_job"type="text"/><br/>
<inputname="btn"type="submit"value="提交表单"/><br/>
</form>
</body>
</html>

3.运行效果:

D. php表单提交到数据库。请问如何写r_save.php的代码

<?php
$username = xxx; //数据库用户名
$password = xxx; //数据库密码
$con = mysql_connect("localhost",$username,$username);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("my_db", $con);
mysql_query("INSERT INTO person (id, name, sex, phone, room_id, seat, date1, opinion)
VALUES ('$_POST[id]', '$_POST[name]', '$_POST[sex]', '$_POST[phone]', '$_POST[room_id]', '$_POST[seat]', ''$_POST[date1]', '$_POST[option]')");
mysql_close($con);
?>

E. PHP写一个代码 怎么做一个提交表单

楼上的Javascript方法可行,但如果用户关闭Javascript支持就不起作用了。补充PHP代码

<?php
if(!empty($_POST['str'])) {
header("Location: http://www.abc.com/qq/".$_POST['str']."/sina");
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="text" size="16" name="str" value="" /> <input type="submit" value="Submit" />
</form>

F. 用php语言编写提交表单的代码 急求 求高手解答

加密的方法是md5()加密
密码+常量方式
define(ALL_PS,"php");
例如echo md5('admin'.ALL_PS);
然后把打印出来的密码串插入数据库
数据库和表的结构就自己创建吧,很简单的

下面是方法是读取数据库中的密码,然后开始登陆的密码再加密和数据库中读取的比较,如果比较结果相同,则登录成功
public function Get_user_login($username, $password) {
$username= str_replace(" ","", $_POST[username]);
$sql="select * from register where `username` = '$username'";
$query=$this->query($sql);

$us=is_array($row=$this->fetch_array($query));

$ps = $us ? md5($password.ALL_PS) == $row[password] : FALSE;
if($ps) {
$_SESSION[uid]=$row[uid];
$_SESSION[user_shell]=md5($row[username].$row[password].ALL_PS);
echo"<script>alert('登录成功 ');location.href='admin.php'</script>";
}else{
echo"<script>alert('密码或用户名错误');location.href='admin_index.php'</script>";
session_destroy();
}
}

G. PHP提交表单发送邮件的代码!50分求!

加载这个类就好了
<?
set_time_limit(120);

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 $sender;

/* Private Variables */
var $sock;

/* Constractor */

function smtp($relay_host = "", $smtp_port = 25,$auth = false,$user,$pass,$sender)
{
$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->sender = $sender;

$this->host_name = "localhost"; //is used in HELO command

$this->log_file = "";

$this->logs = ""; //记录跟服务器的交互过程

$this->sock = FALSE;
}

/* Main Function */

function sendmail($to, $from, $subject = "", $body = "", $mailtype, $cc = "", $bcc = "", $additional_headers = "")
{
$sent = TRUE;

$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 .= "From: ".$from."\r\n";

$header .= "Subject: ".$subject."\r\n";

$header .= $additional_headers;

$header .= "Date: ".date("r")."\r\n";

$header .= "X-Mailer: 72e.net (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)));

}

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");

}

#auth

if($this->auth){

if (!$this->smtp_putcmd("AUTH LOGIN", base64_encode($this->user))) {

return $this->smtp_error("sending AUTH command");

}

if (!$this->smtp_putcmd("", base64_encode($this->pass))) {

return $this->smtp_error("sending AUTH command");

}

}

#

//if (!$this->smtp_putcmd("MAIL", "FROM:".$from."")) {
if (!$this->smtp_putcmd("MAIL", "FROM:<".$this->sender.">")) {

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 <CR><LF>.<CR><LF> [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));

//echo "response=".$response."\r\n";

$this->smtp_debug($response."\n");

//echo "ereg 23 ==".ereg("^[23]", $response)."\n";

if (!ereg("^[23]", $response)) {

//echo "@@@@@";

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");

//echo "cmd=".$cmd."\r\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->logs .= $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;

}

}

} // end class
?>

<?

$smtpserver = "smtp.126.com"; //smpt服务器,网络可以搜索到
$prot=25; //端口一般都是25,除极个别的除外
$smtpuser = "您的邮箱地址"; //您登录smtp服务器的用户名
$smtppwd = "您的密码"; //您登录smtp服务器的密码
$mailtype = "HTML"; //邮件的类型,可选值是 TXT 或 HTML ,TXT 表示是纯文本的邮件,HTML 表示是 html格式的邮件
$sender = "发件人地址"; //发件人,一般要与您登录smtp服务器的用户名($smtpuser)相同,否则可能会因为smtp服务器的设置导致发送失败
$smtp = new smtp($smtpserver,$prot,true,$smtpuser,$smtppwd,$sender);
//$smtp->debug = true; //是否开启调试,只在测试程序时使用,正式使用时请将此行注释
$to = "[email protected]";//收件人
$subject = "你好";
$body = "<h1>这是一个用 <font color='red'><b> php socket </b></font> 发邮件的测试。
支持SMTP认证!</h1>
";
$send=$smtp->sendmail($to,$sender,$subject,$body,$mailtype);
if($send==1){
echo "邮件发送成功";
}else{
echo "邮件发送失败<br>";
echo "原因:".$this->smtp->logs;
}
?>

H. 如何用PHP实现表单提交

创建go.php,代码如下

<?php

@$username = $_POST['name'];
@$usermessage = $_POST['message'];
if(!empty($username) || !empty($usermessage)){
echo "您的姓名:".$username.",您的留言内容:".$usermessage;
}else{
echo '<form action="go.php" method="post">
您的姓名:<input type="text" name="name"><br><br>
留言内容:<input type="text" name="message">
<button>提交</button>
</form>';


案例截图:

I. PHP表单提交后出现的是自己的PHP代码

像你表单应该是HTML的吧,提交给PHP做处理,像显示代码的话,好像APA没处理啊?你应该在“浏览器”中打开表单,就应该可以了,还有,你可以加入,if语句,如果登陆成功,显示登陆成功,否则,显示失败。我能答的就这么多了!答对的话,给分吧!!

J. php表单怎样提交到当前页面,并用$_POST获取其值

<?php
$username=$_POST['username'];

?>

<form action="" ><input type="text" name="username"><input type="submit" name="submit" value="提交"></form>

form的action属性留空的话就直接提交到当前页面了 后台直接$_POST获取前台传过来的表单域啊

阅读全文

与php表单提交代码相关的资料

热点内容
狗语翻译器app链接怎么下 浏览:903
选择排序算法的流程图 浏览:879
如何对文件夹开启共享 浏览:527
常用的磁盘调度算法 浏览:662
怎么用返利app返利 浏览:127
java代码快速 浏览:241
单片机左移右移后是补1还是0 浏览:597
湛江一号命令 浏览:333
导出命令行 浏览:274
C和php交互 浏览:600
苹果手机里的通讯录如何导入安卓手机 浏览:170
怎么在京东app里面看自己会员等级 浏览:43
emerson服务器怎么短接启动 浏览:559
工控编程人员工资 浏览:397
速成意大利语pdf 浏览:250
连续加减乘除法的算法 浏览:654
用mfc编程实现dda算法 浏览:43
linux命令打开应用 浏览:147
改造后的程序员 浏览:271
数控编程变量 浏览:785