我想听一下名为submitDetails的按钮,这是我的注册按钮。基本上我想将表单中的信息发送到mysql,但那部分现在应该没问题,我希望我的按钮能够收听电话。当被调用时,它应该收集我认为我已经在我的代码行中完成的所有信息但是我不确定我是否正确地完成了那部分(我已经使用了isset($ _ GET ..)而不是$ _POST ??以为我需要在发布之前获取它们......或者我错了吗?
我没有和PhP那么多玩过,我之前没有按过按钮接听电话然后行动所以我不确定..我读的另一种方式是ajax,但它让我很困惑无法理解它,它只能通过发送到另一个PHP页面工作吗?或者我可以将其发送到当前PhP页面中的mysql数据吗?
以下是代码行,请告诉我我的按钮如何收听电话,然后点亮
// here you do whatever you want when button is pressed
好的,这是代码:
<style type="text/css">
body {
background-image: url(http://i45.tinypic.com/2iw61x5.png);
background-color: #333;
}
</style>
<?php
echo "<form><font color='white'><P ALIGN='right'>• Hello guest, please <a href='loginPage.php'><font color='white'>login</font></a> / <a href='registerPage.php'><font color='white'>register</font></a>.</P></font>";
echo "<table width='850' cellpadding='1' cellspacing='1' border='0' align='center' bgcolor='#ECF7F7'>"; // starting from here
echo "<tr><td>
<u><P ALIGN='left'><b><font size='5' color='black'>Register_______________________________________________________________</font></b></P></u>
</td></tr>";
echo "</form></table>";
echo "<table width='850' cellpadding='1' cellspacing='1' border='0' align='center' bgcolor='#ECF7F7'>";
echo "<tr><td>
<TR>
<TD><b><Username: </b></TD>
<TD><input type='text' name='Username' id='Username' size='121.5' /></TD>
</TR>
</td></tr>";
echo "</table>";
echo "<table width='850' cellpadding='1' cellspacing='1' border='0' align='center' bgcolor='#ECF7F7'>";
echo "<tr><td>
<TR>
<TD><b>Password: <b></TD></P>
<TD><input type='password' name='Password' id='Password' size='122' /></TD>
</TR>
</td></tr>";
echo "</table>";
echo "<table width='850' cellpadding='1' cellspacing='1' border='0' align='center' bgcolor='#ECF7F7'>";
echo "<tr><td>
<TR>
<TD><b>Re-Password: <b></TD></P>
<TD><input type='password' name='Re-Password' id='Re-Password' size='118' /></TD>
</TR>
</td></tr>";
echo "</table>";
echo "<table width='850' cellpadding='1' cellspacing='1' border='0' align='center' bgcolor='#ECF7F7'>";
echo "<tr><td>
<TR>
<TD><b>Email: <b></TD></P>
<TD><input type='password' name='EmailAddress' id='EmailAddress' size='126' /></TD>
</TR>
</td></tr>";
echo "</table>";
echo "<form method='post'><divstyle='float:center'><P ALIGN='center'><input type='submit' id='submitDetails' name='submitDetails' value='Register'></P></div></form>";
$username = isset($_GET['Username']);
$password = isset($_GET['Password']);
$repassword = isset($_GET['Re-Password']);
$email = isset($_GET['EmailAddress']);
if(!$email == "" && (!strstr($email,"@") || !strstr($email,".")))
{
echo "<h2>Please enter valid e-mail.</h2>\n";
die ("Thank you.");
}
if(empty($username) || empty($password) || empty($repassword) || empty($email))
{
echo "<h2>Please fill in all fields, click the back button to retry</h2>\n";
die ("Thank you.");
}
$message = "Hello $username" .", We have successfuly recieved all your details and stored in our database, please proceed by logging in the website if havn't already.";
$subject = "Media Registration";
mail("hidden",$subject,$message,$email);
?>
答案 0 :(得分:1)
<style type="text/css">
body {
background-image: url(http://i45.tinypic.com/2iw61x5.png);
background-color: #333;
}
</style>
<?php
echo "<form method='post' action='?'><font color='white'><P ALIGN='right'>• Hello guest, please <a href='loginPage.php'><font color='white'>login</font></a> / <a href='registerPage.php'><font color='white'>register</font></a>.</P></font>";
echo "<table width='850' cellpadding='1' cellspacing='1' border='0' align='center' bgcolor='#ECF7F7'>"; // starting from here
echo "<tr><td>
<u><P ALIGN='left'><b><font size='5' color='black'>Register_______________________________________________________________</font></b></P></u>
</td></tr>";
echo "</table>";
echo "<table width='850' cellpadding='1' cellspacing='1' border='0' align='center' bgcolor='#ECF7F7'>";
echo "<tr><td>
<TR>
<TD><b><Username: </b></TD>
<TD><input type='text' name='Username' id='Username' size='121.5' /></TD>
</TR>
</td></tr>";
echo "</table>";
echo "<table width='850' cellpadding='1' cellspacing='1' border='0' align='center' bgcolor='#ECF7F7'>";
echo "<tr><td>
<TR>
<TD><b>Password: <b></TD></P>
<TD><input type='password' name='Password' id='Password' size='122' /></TD>
</TR>
</td></tr>";
echo "</table>";
echo "<table width='850' cellpadding='1' cellspacing='1' border='0' align='center' bgcolor='#ECF7F7'>";
echo "<tr><td>
<TR>
<TD><b>Re-Password: <b></TD></P>
<TD><input type='password' name='Re-Password' id='Re-Password' size='118' /></TD>
</TR>
</td></tr>";
echo "</table>";
echo "<table width='850' cellpadding='1' cellspacing='1' border='0' align='center' bgcolor='#ECF7F7'>";
echo "<tr><td>
<TR>
<TD><b>Email: <b></TD></P>
<TD><input type='password' name='EmailAddress' id='EmailAddress' size='126' /></TD>
</TR>
</td></tr>";
echo "</table>";
echo "<div style='float:center'><P ALIGN='center'><input type='submit' id='submitDetails' name='submitDetails' value='Register'></P></div></form>";
if(isset($_POST['submitDetails']))
{
$username = $_POST['Username'];
$password = $_POST['Password'];
$repassword = $_POST['Re-Password'];
$email = $_POST['EmailAddress'];
if(!$email == "" && (!strstr($email,"@") || !strstr($email,".")))
{
echo "<h2>Please enter valid e-mail.</h2>\n";
die ("Thank you.");
}
if(empty($username) || empty($password) || empty($repassword) || empty($email))
{
echo "<h2>Please fill in all fields, click the back button to retry</h2>\n";
die ("Thank you.");
}
$message = "Hello $username" .", We have successfuly recieved all your details and stored in our database, please proceed by logging in the website if havn't already.";
$subject = "Media Registration";
mail("zdamagedz@hotmail.co.uk",$subject,$message,$email);
}
?>
我修复了表单标签,我添加了method =“post”和action =“?”为了将数据发布到同一页面,请使用“POST”方法。
我还添加了isset($_POST['submitDetails'])
条件,以检查是否点击了提交按钮。
答案 1 :(得分:0)
好的,在您的代码中,您需要指定位置,请求的位置以及将要发送的所有表单。它必须是一个php文件,它可以从$ _GET或$ _POST数组接收这些数据,读取它们并做你需要的任何事情。使用此表单标签:在当前文件的相同位置创建一个名为formPost.php的文件,打开并写入:这可能会让您看到现在的位置