使用html获取php页面以正确提交数据
最初,我有一个问题html页面,需要输入一系列字段,如下所示:使用html获取php页面以正确提交数据,php,html,forms,Php,Html,Forms,最初,我有一个问题html页面,需要输入一系列字段,如下所示: <input type=text name="email" id="email"> 这将使用通过onsubmit启动的php文件提交到sql数据库中。现在我将其更改为一个php页面,以便在页面中包含一个php文件。但是现在我不能再提交数据了。那么,提交这些数据的最佳方式是什么?我可以在表单标签中包含php吗 Questions.php <form action = "registerA3.php" >
<input type=text name="email" id="email">
这将使用通过onsubmit启动的php文件提交到sql数据库中。现在我将其更改为一个php页面,以便在页面中包含一个php文件。但是现在我不能再提交数据了。那么,提交这些数据的最佳方式是什么?我可以在表单标签中包含php吗
Questions.php
<form action = "registerA3.php" >
<fieldset><legend>Register here </legend>
<label for "user">User name </label> <input type=text name="user" id="user" required autofocus=on><br>
<!--these 2 fields will be checked aganist each other for a correct pass. optional show password box because why not -->
<label for "userPass">Password </label><input type=password name="userPass" id="userPass" autocomplete=off required > <input type = checkbox id = "checkbox" onclick="See()"> Click to see password<br>
<label for "chkuserPass">Confirm Password </label><input type=password name="chkuserPass" id="chkuserPass" autocomplete=off required onblur="pwcheck()">
<span id="usrNotify" style="color:red"> </span>
<br><br><br>
<!-- used to warn the user of an incorrect pw -->
<span id="usrNotify"> </span>
<label for "email">Email </label><input type=text name="email" id="email">
<input type=checkbox name="sendEmail" id="sendEmail" > Check for mail copy
<br><br>
<label for "fullname">Full name </label><input type=text name="fullname" id="fullname"><br>
...etc, until the end of the page
在这里注册
用户名
密码点击查看密码
确认密码
电子邮件
检查邮件副本
全名
…等等,直到页面结束
registerA3.php
<?php
include ("account.php");
include ("myfunctions.php");
($dbh = mysql_connect ( $hostname, $username, $password ))
or die ( "Unable to connect to MySQL database" );
print "Connected to MySQL <br>";
mysql_select_db( $project );
//get data from html form
$username = $_GET ["user"];
$password = $_GET ["userPass"];
$email = $_GET ["email"];
$fullname = $_GET ["fullname"];
$major = $_GET ["major"];
$cell = $_GET ["cell"];
//start to get parts of address field
$towns = $_GET ["towns"];
$address = $_GET ["address"];
$states = $_GET ["states"];
$zip = $_GET ["zipcode"];
//put em together
$addressFinal = $towns . $address . $states . $zip;
//use RES to sanitize input
$password = mysql_real_escape_string($password);
$username = mysql_real_escape_string($username);
$email = mysql_real_escape_string($email);
$fullname = mysql_real_escape_string($fullname);
$major = mysql_real_escape_string($major);
$cell = mysql_real_escape_string($cell);
$addressFinal = mysql_real_escape_string($addressFinal);
//sha1 $password, if needed later. remove before submitting if you dont
$hashpw = sha1($password);
//check if the user is already in the registered table. if they are, quit
if ( Rnum($username, $email) > 0)
{
die ( "$username and $email are already in the database! Ending. <br><br> Bye!" );
};
//if it isnt, add it
$s = "insert into registered values ( '$username', '$email', '$hashpw', '$fullname', '$cell', '$addressFinal', NOW(), '$major', 0 ) ";
( $t = mysql_query ( $s ) ) or die ( mysql_error() );
print "$username was added to registered! <br><br> ";
//get info that was just added, since it will match username
$l = "select * from registered where user='$username' ";
( $x = mysql_query ( $l ) ) or die ( mysql_error() );
//start table row
$table = "<table> <tr> <td> <b> Username </b> </td> <td> <b> Email </b> </td> <td> <b> Full Name </b> </td> <td> <b> cell </b> </td> <td> <b> Address </b> </td> <td> <b> Registered </b> </td> <td> <b> Major </b> </td> </tr>";
while ( $r = mysql_fetch_array($x) )
{
//get data to print into table
$username = $r["user"];
$email = $r["email"];
$fullname = $r["fullname"];
$cell = $r["cell"];
$address = $r["address"];
$registTime = $r["regist_datetime"];
$major = $r["major"];
//properly formatted table now
$table .= " <tr> <td> $username </td> <td> $email </td> <td> $fullname </td> <td> $cell </td> <td> $address </td> <td> $registTime </td> <td> $major </td> </tr> ";
}
$table .= "\n\r </table>";
print "$table";
?>
当您说“但是现在我不能再提交数据”时,您的意思是当您单击提交时表单本身不做任何事情,还是当它到达registerA3.php
页面时表单提交但不记录?这两个文件在同一个目录中吗?当我单击提交时,不会发生任何事情。我想它至少会抛出一个错误,但没有什么是的,它们在标签上是@terminus,应该是for=…
?是否不需要=
?