-1
  • Intro

Hello. I am a student that studies Computer Science, and we are assigned to create a web that allows student to take an online quiz.

  • What is my problem?

There are these PHP files named 'daftarmurid' and 'daftarguru'. They are the sign up forms. We supposed to copy all of the codes from the module book.

Unfortunately, when I put those PHP files in a web browser, there are pile of text stuck on the top of the page.

  • What have I tried?
  1. I have contacted the book author herself. She sent me her codes. I have copied it perfectly but the results are still same.

  2. I have tried to copy the error display code from this website, hoping that it will show all the errors. They told me to make the 'php.ini' file. I don't know how.

  3. Playing peek-a-boo with my laptop. Still same. :(

  • The Code

This is from the 'daftarmurid' file.

<!-- Sistem Aplikasi Kuiz -->
<!-- File: daftarmurid.php -->

<?php
// fail sambungan ke pangkalan data
include 'sambungdb.php';

// tetapkan error = false
$error = false;
?>

<?php
if (isset($_POST['daftar'])) {
    //dapatkan data daripada input dan tetapkan pemboleh ubah
    $nokpmurid = $_POST['nokpmurid'];
    $nama = $_POST['nama'];
    $namapengguna = $_POST['namapengguna'];
    $kelas = $_POST['kelas'];
    $katalaluan = $_POST['katalaluan'];
    
    //jika masukkan nama penuh mempunyai nombor atau simbol
    if(!preg_match('/^[a-zA-Z]+$/', $nama)) {
        $error = true;
        $nama_error = "Nama mesti mengandungi huruf sahaja.";
    }
    
    //jika username menpunyai nombor atau simbol
    if(!preg_match('/^[a-zA-Z]+$/', $namapengguna)) {
        $error = true;
        $username_error = "Nama pengguna mesti mengandungi huruf sahaja.";
    }
    
    //jika nokp kurang daripada 12 angka
    if(strlen($nokpmurid) < 12) {
        $error = true;
        $nokp_error = "Masukkan no kad pengenalan dengan betul.";
    }
    
    //jika nokp lebih daripada 12 angka
    if(strlen($nokpmurid) > 12) {
        $error = true;
        $nokp_error = "Masukkan no kad pengenalan dengan betul tanpa '-'.";
    }
    
    //jika kata laluan kurang daripada 6 aksara
    if(strlen($katalaluan) < 6) {
        $error = true;
        $pwd_error = "Kata laluan minimum 6 aksara.";
    }
    
    //jika kata laluan lebih daripada 12 aksara
    if(strlen($katalaluan) > 12) {
        $error = true;
        $pwd_error = "Kata laluan maksimum 12 aksara.";
    }
    
    //tambah rekod baru ke jadual murid
    if (!$error) {
        if ($query = "INSERT INTO murid VALUES (nokpmurid, namapengguna, nama, kelas, katalaluan)") {
            //paparan jika maklumat berjaya didaftar ke jadual murid
            echo "<script>alert('Berjaya didaftarkan! Sila log masuk.');</script>";
        } 
        else {
            //paparan jika maklumat gagal didaftar ke jadual murid
            echo "<script>alert('Ralat! Cuba periksa semula.');</script>";
            }
        }
    }
?>
    
<!-- USER INTERFACE -->
<!DOCTYPE html>
<html lang="en" dir="ltr">
    <head>
        <meta charset= "utf-8">
        <title>VQUIZ</title>
        <!--sambungan fail css -->
        <link rel="stylesheet" href="w3.css">
    </head>
    
    <body>
        <div class= "w3-center" style="width:55%"; margin: 0px auto;">
            <p class="w3-sacramento">VQUIZ</p>
                <div class= "w3-container w3-indigo">
                <p>Daftar Murid</p>
                <!-- BORANG PENDAFTARAN MURID BARU -->
                <form action="daftarmurid.php" method="post">
                    
                    <!-- Nama Penuh -->
                    <input class="w3-input w3-center" type="text" name="nama"
                    required placeholder="Nama Penuh">
                    <span style="color:red"><?php if(isset($nama_error)) echo $nama_error; ?>
                    </span>
                    
                    <!-- No Kad Pengenalan -->
                    <input class="w3-input w3-center" type="text" name="nokp"
                    required placeholder="No Kad Pengenalan (Contoh:020808125151)">
                    <span style="color:red"><?php if (isset($nokp_error))
                    echo $nokp_error; ?></span>
                    
                    <!-- Nama Pengguna -->
                    <input class="w3-input w3-center" type="text" name="username"
                    required placeholder="Username">
                    <span style="color:red"><?php if (isset($username_error)) echo
                    $username_error; ?></span>
                    
                    <!-- Kelas -->
                    <input class="w3-input w3-center" type="text" name="kelas"
                    required placeholder="Kelas">
                    
                    <!-- Kata Laluan -->
                    <input class="w3-input w3-center" type="password" name="pwd"
                    required placeholder="Kata Laluan">
                    <span style="color:red"><?php if (isset($pwd_error))echo
                    $pwd_error; ?></span>
                    
                    <br>
                    <button class="w3-button w3-blue" type="submit"
                    name="daftar">DAFTAR</button>
                    <hr>
                    <h6><a href="logmasukmurid.php">Log Masuk di sini</a></h6>
                </form>
                <!-- TAMAT BORANG PENDAFTARAN -->
            </div>
        </div>
    </body>
</html>


<?php
// periksa ralat
    ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
?>

                    
    

Try to copy these codes, put it in a coding program, save it as '.php' and put it in a web browser. You might know something about it.

  • A little extra help.

These are the codes that were sent by the author herself.

Link:

(Daftar Guru) https://drive.google.com/file/d/1M3P4drI6DSEqah32M43u6_vUt3MrEqYz/view?usp=sharing

(Daftar Murid) https://drive.google.com/file/d/1LR3UdyQmGKC0bo68siy8ZnD2NhXj6NUN/view?usp=sharing

The screenshot... The Pain :(

Bye-bye! :)

3 Answers3

2

you need to use web server software to run a php file like xampp, apache, nginx etc. you can't just run php file like html file by putting it on a browser.

HazelR
  • 57
  • 10
0

PHP scripts are executed and processed on the server. If you are running the script from a server and still get the errors, It will be helpful if you share a screenshot of the same. Also ensure that your include file is existing and referenced appropriately to avoid php form raising other include errors // fail sambungan ke pangkalan data include 'sambungdb.php';

Antony
  • 161
  • 3
  • 4
0

Yeah, I finally found the answer. If you want to launch the web properly, you have to put your web folder in the 'htdocs' folder. It can be found inside the XAMPP file.

And then, you should type 'localhost/yourwebname' on the browser.