i'm having a problem to my website when i'm clicking it , its just downloading and not even loading for the next page. what can i do? what should i change? i'm just a newbie in html and php , by the way the file i was click is a php file that i made and it is not directing to next page the file was downloading when i click that php file. i was wondering if someone help me here , thanks in advance for someone who might help me. it is just for my project. http://itweb.bitballoon.com/ this is the website when i'm clicking the sign and register it will download the file of php i dont know how to solve this problem i search already in youtube and google. i cant see a single answer. someone help me please thanks.
codes of register.php
<?php
ob_start();
session_start();
if( isset($_SESSION['user'])!="" ){
header("Location: home.php");
}
include_once 'dbconnect.php';
$error = false;
if ( isset($_POST['btn-signup']) ) {
// clean user inputs to prevent sql injections
$firstname = trim($_POST['firstname']);
$firstname = strip_tags($firstname);
$firstname = htmlspecialchars($firstname);
$middlename = trim($_POST['middlename']);
$middlename = strip_tags($middlename);
$middlename = htmlspecialchars($middlename);
$lastname = trim($_POST['lastname']);
$lastname = strip_tags($lastname);
$lastname = htmlspecialchars($lastname);
$student_number = trim($_POST['student_number']);
$student_number = strip_tags($student_number);
$student_number = htmlspecialchars($student_number);
$course = $_POST['course'];
$pass = trim($_POST['pass']);
$pass = strip_tags($pass);
$pass = htmlspecialchars($pass);
// basic name validation
if (empty($firstname)) {
$error = true;
$firstnameError = "Please enter your firstname.";
} else if (strlen($firstname) < 2) {
$error = true;
$firstnameError = "Firstname must have atleat 2 characters.";
} else if (!preg_match("/^[a-zA-Z ]+$/",$firstname)) {
$error = true;
$firstnameError = "Firstname must not contain numbers or special characters.";
}
if (!empty($middlename) && !preg_match("/^[a-zA-Z ]+$/",$middlename)) {
$error = true;
$middlenameError = "Middlename must not contain numbers or special characters.";
}
if (empty($lastname)) {
$error = true;
$lastnameError = "Please enter your lastname.";
} else if (strlen($lastname) < 2) {
$error = true;
$lastnameError = "Lastname must have atleat 2 characters.";
} else if (!preg_match("/^[a-zA-Z ]+$/",$lastname)) {
$error = true;
$lastnameError = "Lastname must not contain numbers or special characters.";
}
if (empty($course)) {
$error = true;
$courseError = "Please select a course.";
}
if (empty($student_number)) {
$error = true;
$student_numberError = "Please enter your student number.";
} else if (!(strlen($student_number) >= 12 && strlen($student_number) <= 13)) {
$error = true;
$student_numberError = "Student number must have atleat 12 characters.";
} else if (!preg_match("/^PM-[0-9]{2}-[0-9]{4,5}-[AB]$/", $student_number)) {
$error = true;
$student_numberError = "Invalid student number format.";
} else {
//check if student number exists
$result = mysql_query("SELECT * FROM users WHERE student_number = '$student_number'");
$rowCount = mysql_num_rows($result);
if ($rowCount == 1) {
$error = true;
$student_numberError = "Student number is already taken.";
}
}
// password validation
if (empty($pass)){
$error = true;
$passError = "Please enter password.";
} else if(strlen($pass) < 6) {
$error = true;
$passError = "Password must have atleast 6 characters.";
}
// password encrypt using SHA256();
$password = hash('sha256', $pass);
// if there's no error, continue to signup
if( !$error ) {
$query = "INSERT INTO users(student_number,userPass,user_role,firstname,middlename,lastname,course) VALUES('$student_number','$password',2,'$firstname','$middlename','$lastname',$course)";
$res = mysql_query($query);
if ($res) {
$errTyp = "success";
$errMSG = "Successfully registered, you may login now.";
unset($firstname);
unset($middlename);
unset($lastname);
unset($course);
unset($student_number);
unset($pass);
} else {
$errTyp = "danger";
$errMSG = "Something went wrong, try again later...";
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Coding Cage - Login & Registration System</title>
<link rel="stylesheet" href="assets/css/bootstrap.min.css" type="text/css" />
<link rel="stylesheet" href="style.css" type="text/css" />
<script type="text/javascript" src="assets/js/jquery-3.2.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#course').change(function () {
if ($(this).val() == '') {
$(this).css('color', '#999');
}
else {
$(this).css('color', '#000');
}
$('option').css('color', '#000');
});
$('#course').trigger('change');
});
</script>
</head>
<body>
<div class="container">
<div id="login-form">
<form method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" autocomplete="off">
<div class="col-md-12">
<div class="form-group">
<h2 class="">Sign Up.</h2>
</div>
<div class="form-group">
<hr />
</div>
<?php
if ( isset($errMSG) ) {
?>
<div class="form-group">
<div class="alert alert-<?php echo ($errTyp=="success") ? "success" : $errTyp; ?>">
<span class="glyphicon glyphicon-info-sign"></span> <?php echo $errMSG; ?>
</div>
</div>
<?php
}
?>
<div class="form-group">
<div class="input-group ">
<span class="input-group-addon"><span class="glyphicon glyphicon-user"></span></span>
<input type="text" name="firstname" class="form-control" placeholder="Firstname" maxlength="50" value="<?php echo $firstname ?>" />
</div>
<span class="text-danger"><?php echo $firstnameError; ?></span>
</div>
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-user"></span></span>
<input type="text" name="middlename" class="form-control" placeholder="Middlename" maxlength="50" value="<?php echo $middlename ?>" />
</div>
<span class="text-danger"><?php echo $middlenameError; ?></span>
</div>
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-user"></span></span>
<input type="text" name="lastname" class="form-control" placeholder="Lastname" maxlength="50" value="<?php echo $lastname ?>" />
</div>
<span class="text-danger"><?php echo $lastnameError; ?></span>
</div>
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-book"></span></span>
<select id="course" name="course" class="form-control">
<option <?php echo $course == "1" ? "selected" : "" ?> value="1">BSIT</option>
<option <?php echo $course == "2" ? "selected" : "" ?> value="2">BSBA</option>
<option <?php echo $course == "3" ? "selected" : "" ?> value="3">BSTM</option>
<option <?php echo $course == "4" ? "selected" : "" ?> value="4">BSHRM</option>
<option <?php echo $course == "5" ? "selected" : "" ?> value="5">BSN</option>
<option <?php echo $course == "6" ? "selected" : "" ?> value="6">BSC</option>
<option <?php echo $course == "7" ? "selected" : "" ?> value="7">BSA</option>
<option <?php echo $course == "8" ? "selected" : "" ?> value="8">BSE</option>
<option <?php echo $course == "9" ? "selected" : "" ?> value="9">ABMC</option>
<option <?php echo $course == "10" ? "selected" : "" ?> value="10">BSP</option>
<option <?php echo $course == "11" ? "selected" : "" ?> value="11">BAPA</option>
</select>
</div>
<span class="text-danger"><?php echo $courseError; ?></span>
</div>
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-user"></span></span>
<input type="text" name="student_number" class="form-control" placeholder="Student Number" maxlength="50" value="<?php echo $student_number ?>" />
</div>
<span class="text-danger"><?php echo $student_numberError; ?></span>
</div>
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></span>
<input type="password" name="pass" class="form-control" placeholder="Password" maxlength="15" />
</div>
<span class="text-danger"><?php echo $passError; ?></span>
</div>
<div class="form-group">
<hr />
</div>
<div class="form-group">
<button type="submit" class="btn btn-block btn-primary" name="btn-signup">Sign Up</button>
</div>
<div class="form-group">
<hr />
</div>
<div class="form-group">
<a href="Login.php">Sign in Here...</a>
</div>
</div>
</form>
</div>
</div>
</body>
</html>
<?php ob_end_flush(); ?>
Sign in codes :
<?php
ob_start();
session_start();
require_once 'dbconnect.php';
if ( isset($_SESSION['user'])!="" ) {
header("Location: home.php");
exit;
}
$error = false;
if( isset($_POST['btn-login']) ) {
// prevent sql injections/ clear user invalid inputs
$student_number = trim($_POST['student_number']);
$student_number = strip_tags($student_number);
$student_number = htmlspecialchars($student_number);
$pass = trim($_POST['pass']);
$pass = strip_tags($pass);
$pass = htmlspecialchars($pass);
// prevent sql injections / clear user invalid inputs
if(empty($student_number)){
$error = true;
$student_number_Error = "Please enter your student number.";
}
if(empty($pass)){
$error = true;
$passError = "Please enter your password.";
}
// if there's no error, continue to login
if (!$error) {
$password = hash('sha256', $pass); // password hashing using SHA256
$res=mysql_query("SELECT student_number, userPass, user_role, firstname, middlename, lastname, course FROM users WHERE student_number = '$student_number'");
$row=mysql_fetch_array($res);
$count = mysql_num_rows($res); // if uname/pass correct it returns must be 1 row
if( $count == 1 && $row['userPass']==$password ) {
$_SESSION['user'] = $row['student_number'];
header("Location: home.php");
echo $_GET['id'];
} else {
$errMSG = "Incorrect Credentials, Try again...";
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Coding Cage - Login & Registration System</title>
<link rel="stylesheet" href="assets/css/bootstrap.min.css" type="text/css" />
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<div class="container">
<div id="login-form">
<form method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" autocomplete="off">
<div class="col-md-12">
<div class="form-group">
<h2 class="">Sign In.</h2>
</div>
<div class="form-group">
<hr />
</div>
<?php
if ( isset($errMSG) ) {
?>
<div class="form-group">
<div class="alert alert-danger">
<span class="glyphicon glyphicon-info-sign"></span> <?php echo $errMSG; ?>
</div>
</div>
<?php
}
?>
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-user"></span></span>
<input type="text" name="student_number" class="form-control" placeholder="Student Number" value="<?php echo $student_number; function a(){$student_number=$idc;}?>" maxlength="15" />
</div>
<span class="text-danger"><?php echo $student_number_Error; ?></span>
</div>
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></span>
<input type="password" name="pass" class="form-control" placeholder="Password" maxlength="30" />
</div>
<span class="text-danger"><?php echo $passError; ?></span>
</div>
<div class="form-group">
<hr />
</div>
<div class="form-group">
<button type="submit" class="btn btn-block btn-primary" name="btn-login">Sign In</button>
</div>
<div class="form-group">
<hr />
</div>
<div class="form-group">
<a href="register.php">Sign Up Here...</a>
</div>
</div>
</form>
</div>
</div>
</body>
</html>
<?php ob_end_flush(); ?>
Error message is: Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /storage/ssd5/266/3359266/public_html/dbconnect.php:11 Stack trace: #0 /storage/ssd5/266/3359266/public_html/login.php(4): require_once() #1 {main} thrown in /storage/ssd5/266/3359266/public_html/dbconnect.php on line 11