{ "key_pair_value_system": true, "answer_rating_count": "", "question_feedback_html": { "html_star": "", "html_star_feedback": "" }, "answer_average_rating_value": "", "answer_date_js": "2024-09-09T07:06:26-04:00", "answer_date": "2024-09-09 07:06:26", "is_docs_available": null, "is_excel_available": null, "is_pdf_available": null, "count_file_available": 0, "main_page": "student_question_view", "question_id": "9785718", "url": "\/study-help\/questions\/why-will-this-code-not-work-9785718", "question_creation_date_js": "2024-09-09T07:06:26-04:00", "question_creation_date": "Sep 09, 2024 07:06 AM", "meta_title": "[Solved] why will this code not work? Chinese Zodi | SolutionInn", "meta_description": "Answer of - why will this code not work? Chinese Zodiac Networking body, .navbar navbar-default { backgroung-color: rgb(235,244,25 | SolutionInn", "meta_keywords": "will,code,work,chinese,zodiac,networking,body,navbar,navbar-default,backgroung-color,rgb,235,244,251", "question_title_h1": "why will this code not work? Chinese Zodiac Networking body, .navbar navbar-default { backgroung-color: rgb(235,244,251); } Toggle navigation Chinese Zodiac Social Networking Login Register Register", "question_title": "why will this code not work? Chinese Zodiac Networking body, .navbar navbar-default", "question_title_for_js_snippet": "why will this code not work ", "question_description": "
why will this code not work?<\/p>
<\/p>
session_start();<\/p>
if(isset($_SESSION['member_id']))<\/p>
{<\/p>
header(\"Location:index.php\");\/\/redirects to the home page<\/p>
} \/\/ ends isset session<\/p>
<\/p>
\/\/insert the connection script and end the script if the connection fails<\/p>
require_once '..\/..\/..\/..\/..\/inc_connect.php';<\/p>
<\/p>
\/\/function to store password as a hashed value<\/p>
function randomString()<\/p>
{<\/p>
$string = md5(rand());<\/p>
return $string;<\/p>
}<\/p>
\/\/initially there are no erros<\/p>
$error = false;<\/p>
<\/p>
\/\/check if form s submitted<\/p>
if(isset($_POST['register']))<\/p>
{<\/p>
$fname = mysql_real_escape_string($_POST['fname']);<\/p>
$lname = mysql_real_escape_string($_POST['lname']);<\/p>
$email = mysql_real_escape_string($_POST['email']);<\/p>
$password = mysql_real_escape_string($_POST['password']);<\/p>
$cpassword = mysql_real_escape_string($_POST['cpassword']);<\/p>
<\/p>
<\/p>
\/\/validate form data<\/p>
\/\/fname can contain only letters and spaces<\/p>
if(!preg_match('\/^[a-zA-Z\\s]+$\/',$fname))<\/p>
{<\/p>
$error = true;<\/p>
\/\/message to member if error occurs<\/p>
$fname_error = \"Name must contain only letters and spaces\";<\/p>
}<\/p>
\/\/lname can contain only letters and spaces<\/p>
if(!preg_match('\/^[a-zA-Z\\s]+$\/',$lname))<\/p>
{<\/p>
$error = true;<\/p>
\/\/message to member if error occurs<\/p>
$lname_error = \"Name must contain only letters and spaces\";<\/p>
}<\/p>
\/\/validate email to valid maine account<\/p>
if(!preg_match('\/^[a-zA-Z\\.]+@(unit\\.maine|maine)\\.edu\/', $email))<\/p>
{<\/p>
$error = true;<\/p>
\/\/message to member if error occurs<\/p>
$email_error = \"Please enter a valid University account.\";<\/p>
}\/\/ ends email<\/p>
\/\/text striing with at lease one Number and one Character between 6 and 10 characters<\/p>
if(strlen($password) < 7)<\/p>
{<\/p>
$error = true;<\/p>
$password_error = \"Password must be minimum of 7 characters.\";<\/p>
}<\/p>
if($password != $cpassword)<\/p>
{<\/p>
$error = true;<\/p>
\/\/messare to member if error occurs<\/p>
$cpassword_error = \"Password and Comfirm Password do not match.\";<\/p>
}<\/p>
if(!$error)<\/p>
{<\/p>
\/\/hash and salt the password to make it more secure<\/p>
$hash = \"\";<\/p>
$password = $_POST['password'];<\/p>
$salt = randomString();<\/p>
$hash = md5($password.$salt);<\/p>
$TableName = \"members\"; \/\/assign the table name to a variable<\/p>
\/\/insert posted data to the mebers table<\/p>
$SQLString = \"INSERT INTO $TableName \" .<\/p>
\"(fname, lname, password_hash, password_salt) VALUES\" .<\/p>
\"('$fname', '$lname', '$email', '$hash', '$salt')\";<\/p>
$QueryResults = @mysql_query($SQLString, $DBConnect);<\/p>
if($QueryResults)<\/p>
{<\/p>
\/\/message on successful registration<\/p>
$successmsg = \"Successfully Registered! Click here to Login\";<\/p>
}\/\/ends if QR<\/p>
else<\/p>
{<\/p>
\/\/message on uncuccessful registration<\/p>
echo mysql_error();<\/p>
$errormsg = \"Error in registering... Pleae try again later!.\";<\/p>
}\/\/ends else QR<\/p>
<\/p>
}\/\/ends if !$error<\/p>
<\/p>
}\/\/ends isset for register<\/p>
?><\/p>
<\/p>
<\/p>
<\/p><\/p>
<\/p>
<\/p>