Thanks a lot prometheuzz, everything's working fine now. I have this one to ask again-
My registration form, gives error messages through alert boxes properly now on wrong input. But every time there is a wrong input, on submission of the form, i am directed to the "do_register.php" page along with the alert box. The new page says "Connection successful Could not execute query".
What i want is that on clicking the submit button, if there are any wrong inputs, i want only the alert box with the message but on the same "register.php page, so that i don't have to return back every time. Moreover, the database gets populated each time i click on submit.
This is "register.php"
Code: Select all
<?php
include "header1.php";
?>
<div id="content">
<div id="left" style="left: 0px; top: 0px">
<ul>
<li>Email address :</li>
<li>Preferred username :</li>
<li>Password :</li>
<li>Confirm password :</li>
</ul>
</div>
<div id="right">
<p style="left: -1px; top: 0px"><font size="4.5px">REGISTER</font></p>
<form action="do_register.php">
<input type="text" size="20" name="email"><br><br>
<input type="text" size="20" name="username"> (max 16 chars)<br><br>
<input type="password" size="20" name="passwd"> (6 to 16 chars)<br><br>
<input type="password" size="20" name="passwd2"><br><br>
<input type="submit" name="Submit" value="submit">
<input type="reset" name="Reset" value="reset">
</form>
</div>
</div>
<?php
include "footer.php";
?>
And this is "do_register.php"
Code: Select all
<?php
include "header1.php";
?>
<div id="content">
<?php
//include function files for this application
require("PDMS_fns.php");
// start session which may be needed later
// start it now because it must go before headers
session_start();
// email address not valid
if (!valid_email($email))
{
print("<script language = 'javascript'>alert('Not a valid email address');</script>");
exit();
}
// check username length
if(($username == "" ) || strlen($username)>16)
{
print("<script language = 'javascript'>alert('Username must be from 1 to 16 characters');</script>");
exit();
}
// passwords not same
if($passwd != $passwd2)
{
print("<script language = 'javascript'>alert('Passwords donot match');</script>");
exit();
}
// check password length is ok
// ok if username truncates, but passwords will get munged if they are too long.
if (strlen($passwd)<6 || strlen($passwd) >16)
{
print("<script language = 'javascript'>alert('Password must be between 6 to 16 characters');</script>");
exit();
}
// attempt to register
$reg_result = register($username, $email, $passwd);
if($reg_result == "true")
{
// register session variable
$valid_user = $username;
session_register("valid_user");
// provide link to members page
echo "You have been registered as $valid_user -go to members page and start";
}
else
{
// otherwise, provide link back, tell them to try again
echo $reg_result;
exit();
}
?>
</div>
<?php
include "footer.php";
?>