spiritssight
01-22-2008, 10:58 PM
Hello All,
I have wrote the following script and I am looking for feed back and advice on improving it. I don't have form validation in it yet, I am slowly trying to work on a validation function (be posting that soon).
Any how the create account script does:
displays form, person enters data, it then displays there input but not there password, at that time it also encrpyted the password so if someone reads the source of the file they would not see it in plain text, once the person hits submit, it checks to see if the email address that has been entered is in the user table, if it is it tells them (future it will redirect) and if now it creates the account
<?php
if(isset($_POST['next']))
{
$salt = "123abc123abccba321cba321";
$_POST['user_password'] = md5($salt . $_POST['user_password'] . $salt);
$_POST['verify_user_password'] = md5($salt . $_POST['verify_user_password'] . $salt);
echo '
<form action ="create_account.php" method="post">
<input type="hidden" value="'. $_POST['f_name'] .'" id="f_name" name="f_name" />
<input type="hidden" value="'. $_POST['m_inital'] .'" id="m_inital" name="m_inital" />
<input type="hidden" value="'. $_POST['l_name'] .'" id="l_name" name="l_name" />
<input type="hidden" value="'. $_POST['email_address'] .'" id="email_address" name="email_address" />
<input type="hidden" value="'. $_POST['user_password'] .'" id="user_password" name="user_password" />
<input type="hidden" value="'. $_POST['verify_user_password'] .'" id="verify_user_password" name="verify_user_password" />
<p>PLease look at the information and make sure its correct!</p>
'. $_POST['f_name'] .' '. $_POST['m_inital'] .' '. $_POST['l_name'] .'<br />'. $_POST['email_address'].'<br /><br />
<input type="submit" name="create" value="Create Account" />
</form>
';
}
else if(isset($_POST['create']))
{
include '/home/dev/www/lib/db_config_cr-dev.php';
include '/home/dev/www/lib/db_conn-select.php';
$query_s = "SELECT 'email_address' FROM user_info WHERE email_address = '{$_POST['email_address']}'";
$result_s = mysql_query($query_s) OR die("Sorry, unable to select record: " . mysql_error());
$count_s = mysql_num_rows($result_s);
if($count_s)
{echo 'Your email address is already in our system!';}
else
{
do
{
$user_id = sprintf("%'09d", mt_rand(1, 999999999));
$user_id = "P-".$user_id;
$query_s = "SELECT user_id FROM access_credentials WHERE user_id = '$user_id'";
$result_s = mysql_query($query_s) OR die("Sorry, unable to select record: " . mysql_error());
echo $user_id .'<br />';
}
while(mysql_num_rows($result_s) != 0); // don't do again if = 0
$salt = "123abc123abccba321cba321";
$_POST['user_password'] = md5($salt . $_POST['user_password'] . $salt);
$query_i = "INSERT INTO user_info (user_id, f_name, m_inital, l_name, email_address) VALUES ('$user_id', '$_POST[f_name]','$_POST[m_inital]','$_POST[l_name]','$_POST[email_address]')";
$result_i = mysql_query($query_i) OR die("Sorry was unable to create account (not able to insert into the database table! <br />" . mysql_error());
$count = mysql_affected_rows();
$query_i = "INSERT INTO access_credentials (user_id, user_password, user_access_level) VALUES ('$user_id', '$_POST[user_password]','0')";
$result_i = mysql_query($query_i) OR die("Sorry was unable to insert ".$fin." into the database table allowed! <br />" . mysql_error());
$count = mysql_affected_rows();
if($count)
{
echo "Account Created";
}
}
}
else
{
?>
<form action="create_account.php" method="post">
<label for="f_name">First Name: </label>
<input type="text" value="" id="f_name" name="f_name" /><br />
<label for="m_inital">Middle Inital: </label>
<input type="text" value="" id="m_inital" name="m_inital" /><br />
<label for="l_name">Last Name: </label>
<input type="text" value="" id="l_name" name="l_name" /><br />
<label for="email_address">E-Mail Address: </label>
<input type="text" value="" id="email_address" name="email_address" /><br />
<label for="user_password">Password: </label>
<input type="password" value="" id="user_password" name="user_password" /><br />
<label for="verify_user_password">Verify Password: </label>
<input type="password" value="" id="verify_user_password" name="verify_user_password" /><br />
<input type="submit" name="next" value="submit" /><input type="reset" name="clear" value="Clear" />
</form>
<?php
}
?>
I would really like to have this as three different files, one for form, preview, validating, and processing
the way I am hoping my validation works will be if the person entered some of the information right and others wrong the only stuff that would be displayed would be the wrong information, any ideas would be great on that?
thanks ahead of time for your advice and time for the help!
Sincerely,
Christopher
I have wrote the following script and I am looking for feed back and advice on improving it. I don't have form validation in it yet, I am slowly trying to work on a validation function (be posting that soon).
Any how the create account script does:
displays form, person enters data, it then displays there input but not there password, at that time it also encrpyted the password so if someone reads the source of the file they would not see it in plain text, once the person hits submit, it checks to see if the email address that has been entered is in the user table, if it is it tells them (future it will redirect) and if now it creates the account
<?php
if(isset($_POST['next']))
{
$salt = "123abc123abccba321cba321";
$_POST['user_password'] = md5($salt . $_POST['user_password'] . $salt);
$_POST['verify_user_password'] = md5($salt . $_POST['verify_user_password'] . $salt);
echo '
<form action ="create_account.php" method="post">
<input type="hidden" value="'. $_POST['f_name'] .'" id="f_name" name="f_name" />
<input type="hidden" value="'. $_POST['m_inital'] .'" id="m_inital" name="m_inital" />
<input type="hidden" value="'. $_POST['l_name'] .'" id="l_name" name="l_name" />
<input type="hidden" value="'. $_POST['email_address'] .'" id="email_address" name="email_address" />
<input type="hidden" value="'. $_POST['user_password'] .'" id="user_password" name="user_password" />
<input type="hidden" value="'. $_POST['verify_user_password'] .'" id="verify_user_password" name="verify_user_password" />
<p>PLease look at the information and make sure its correct!</p>
'. $_POST['f_name'] .' '. $_POST['m_inital'] .' '. $_POST['l_name'] .'<br />'. $_POST['email_address'].'<br /><br />
<input type="submit" name="create" value="Create Account" />
</form>
';
}
else if(isset($_POST['create']))
{
include '/home/dev/www/lib/db_config_cr-dev.php';
include '/home/dev/www/lib/db_conn-select.php';
$query_s = "SELECT 'email_address' FROM user_info WHERE email_address = '{$_POST['email_address']}'";
$result_s = mysql_query($query_s) OR die("Sorry, unable to select record: " . mysql_error());
$count_s = mysql_num_rows($result_s);
if($count_s)
{echo 'Your email address is already in our system!';}
else
{
do
{
$user_id = sprintf("%'09d", mt_rand(1, 999999999));
$user_id = "P-".$user_id;
$query_s = "SELECT user_id FROM access_credentials WHERE user_id = '$user_id'";
$result_s = mysql_query($query_s) OR die("Sorry, unable to select record: " . mysql_error());
echo $user_id .'<br />';
}
while(mysql_num_rows($result_s) != 0); // don't do again if = 0
$salt = "123abc123abccba321cba321";
$_POST['user_password'] = md5($salt . $_POST['user_password'] . $salt);
$query_i = "INSERT INTO user_info (user_id, f_name, m_inital, l_name, email_address) VALUES ('$user_id', '$_POST[f_name]','$_POST[m_inital]','$_POST[l_name]','$_POST[email_address]')";
$result_i = mysql_query($query_i) OR die("Sorry was unable to create account (not able to insert into the database table! <br />" . mysql_error());
$count = mysql_affected_rows();
$query_i = "INSERT INTO access_credentials (user_id, user_password, user_access_level) VALUES ('$user_id', '$_POST[user_password]','0')";
$result_i = mysql_query($query_i) OR die("Sorry was unable to insert ".$fin." into the database table allowed! <br />" . mysql_error());
$count = mysql_affected_rows();
if($count)
{
echo "Account Created";
}
}
}
else
{
?>
<form action="create_account.php" method="post">
<label for="f_name">First Name: </label>
<input type="text" value="" id="f_name" name="f_name" /><br />
<label for="m_inital">Middle Inital: </label>
<input type="text" value="" id="m_inital" name="m_inital" /><br />
<label for="l_name">Last Name: </label>
<input type="text" value="" id="l_name" name="l_name" /><br />
<label for="email_address">E-Mail Address: </label>
<input type="text" value="" id="email_address" name="email_address" /><br />
<label for="user_password">Password: </label>
<input type="password" value="" id="user_password" name="user_password" /><br />
<label for="verify_user_password">Verify Password: </label>
<input type="password" value="" id="verify_user_password" name="verify_user_password" /><br />
<input type="submit" name="next" value="submit" /><input type="reset" name="clear" value="Clear" />
</form>
<?php
}
?>
I would really like to have this as three different files, one for form, preview, validating, and processing
the way I am hoping my validation works will be if the person entered some of the information right and others wrong the only stuff that would be displayed would be the wrong information, any ideas would be great on that?
thanks ahead of time for your advice and time for the help!
Sincerely,
Christopher