0% found this document useful (0 votes)
7 views3 pages

Code

The document contains a PHP script for a student sign-up form that collects user information such as matric number, first name, last name, class, and password. It includes a database connection to fetch class options and handles form submission via AJAX to register the student in the database. If the registration is successful, a success message is displayed, otherwise, an error message is shown.

Uploaded by

Samuel Ekene
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

Code

The document contains a PHP script for a student sign-up form that collects user information such as matric number, first name, last name, class, and password. It includes a database connection to fetch class options and handles form submission via AJAX to register the student in the database. If the registration is successful, a success message is displayed, otherwise, an error message is shown.

Uploaded by

Samuel Ekene
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

Student_signin_form.

php
<form id="signin_student" class="form-signin" method="post">
<h3 class="form-signin-heading"><i class="icon-lock"></i> LPA Student
Signup</h3>
<input type="text" class="input-block-level" id="username"
name="username" placeholder="Matric Number" required>
<input type="text" class="input-block-level" id="firstname"
name="firstname" placeholder="Firstname" required>
<input type="text" class="input-block-level" id="lastname"
name="lastname" placeholder="Lastname" required>
<label>Class</label>
<select name="class_id" class="input-block-level span5">
<option></option>

<?php
// Ensure proper database connection
include('admin/[Link]');

// Fetch departments from the database


$query = mysqli_query($conn, "SELECT * FROM class ORDER BY class_name") or
die(mysqli_error($conn));
while ($row = mysqli_fetch_array($query)) {
?>
<option value="<?php echo $row['class_id'] ?>"><?php echo
$row['class_name']; ?></option>
<?php
}
?>

</select>
<input type="password" class="input-block-level" id="password"
name="password" placeholder="Password" required>
<input type="password" class="input-block-level" id="cpassword"
name="cpassword" placeholder="Re-type Password" required>
<button id="signin" name="login" class="btn btn-info" type="submit"><i
class="icon-check icon-large"></i> Sign up</button>
</form>

<script>
jQuery(document).ready(function(){
jQuery("#signin_student").submit(function(e){
[Link]();
var formData = jQuery(this).serialize();
$.ajax({
type: "POST",
url: "student_signup.php",
data: formData,
success: function(response){
if(response == 'true') {
$.jGrowl("Welcome to LPA WORLD", { header: 'Sign up
Success' });
var delay = 2000;
setTimeout(function(){ [Link] =
'dashboard_student.php' }, delay);
} else {
$.jGrowl("Failed to sign up. Please try again later.",
{ header: 'Sign Up Failed' });
}
}
}
);
});

});
</script>
<!-- Ensure proper redirection to login page -->
<a href="[Link]" id="btn_login" class="btn"><i class="icon-signin icon-
large"></i> Click here to Login</a>

<?php

Student_signup.php
<?php
include('admin/[Link]');
session_start();

$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$username = $_POST['username'];
$password = $_POST['password'];

$query = "SELECT * FROM student WHERE username=? AND password=?";


$stmt = mysqli_prepare($conn, $query);

// Bind parameters
mysqli_stmt_bind_param($stmt, "ss", $username, $password);

// Execute query
mysqli_stmt_execute($stmt);

// Get result
$result = mysqli_stmt_get_result($stmt);

// Fetch the row


$row = mysqli_fetch_array($result);

// Get the number of rows


$num_row = mysqli_num_rows($result);

$count = mysqli_num_rows($result);

if ($count == 0){

mysqli_query($conn, "INSERT INTO student (firstname, lastname, username,


password, status) VALUES ('$firstname', '$lastname', '$username', '$password',
'Registered')") or die(mysqli_error($conn));

echo 'true';
}else{
echo 'false';
}
?>

You might also like