I want to listen to this button called submitDetails which is my Register button. Basically I want to send the information from the form over to mysql but that part should be ok for now I would like my button to listen to calls. And when called, it should gather all the information which I think I’ve done in my lines of code but I’m not sure If I’ve done that part correctly or not (I’ve used isset($_GET..) instead of $_POST ?? Thought I’d need to GET them before POSTing .. or am I wrong?
I’m havn’t played with PhP that much and I havn’t made a button previously to listen to calls and then act so I’m not sure.. another way I read is ajax but its pretty much confusing I couldn’t get my head around it, it can only work by sending you to another php page right? Or can I make it so it sends data to mysql in the current PhP page?
Here is the lines of code please show me how my button could listen to calls and then put
// here you do whatever you want when button is pressed
Okay here is code:
<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);
?>
I fixed the form tags, I added method=”post” and the action=”?” in order to post the data to the same page, in the “POST” method.
I have also added the
isset($_POST['submitDetails'])condition, in order to check whether the submit button was clicked or not.