hi it is me again, this is my assignemet been trying to fix this php script for a long time

first to begin, it was issuing an error,

Warning: join(): Invalid arguments passed in C
this is the first error

and the second error was: notice: undefined index in c.
apprently if my html code, i had register a the values when registering but in my php code i had enter instead, so i fix it right

now after i finished fixing it, i tried to register a user and now i am getting a blank page, dont know what is the cause but maybe a third eye can see what I cant. please help
here is what i have tried.

<?php

        //$register=$_POST['register_user']; 
         if(isset($_POST['register']))
        {

            //capture the variable from the form and store in php variables
            $title=$_POST['title'];
            $firstname=$_POST['fname'];
            $lastname=$_POST['lname'];
            $username=$_POST['username'];
            $email=$_POST['email'];
            $gender=$_POST['gender'];
            $service= join(", ", $_POST['services']);
            $address=$_POST['address'];
            $mypwd=$_POST['mypwd'];

            include'db_server.php';

            //Query the database
            $sql="SELECT * FROM members WHERE username='$username'";

            $result= mysqli_query($conn, $sql) or die ("ERROR:" .mysqli_error($conn));

            $rowcount=mysqli_num_rows($result);

            //checking to see if username is already exist
            if($rowcount >= 1) 
            {
                 echo "<script type=\"text/javascript\">
                      alert('Username already exits');
                      window.location=\"../xhtml/register_user.html\";
                       </script>";

            }
            else
            {
                //insert data into table

                $sql = "INSERT INTO members
                VALUES('$title', '$firstname', '$lastname', '$username', '$email', '$gender', '$service', '$address', md5('$mypwd'))";

                if(mysqli_query($conn,$sql))
                {

                    echo "<script type=\"text/javascript\">
                      alert('Welcome!! $firstname $lastname, you are now a member of the Caribbean Nature Seekers Institute TT(CNSITT)');
                      window.location=\"../index.html\";
                       </script>";

                        mysqli_close($conn);    
                }
                else
                {
                    echo "Error inserting values into database";
                }

                //end of line

            }
        }

?>

Recommended Answers

All 4 Replies

I'd worry more about the sql injection that you've opened yourself up to. Either sanitize or use a prepared statement. Sorry can't examine your code further at the mo other than you must validate all your user input data. The services data seems to be the wrong data type. Are you sure it is an array? If not you can cast it as one. However your html form should do this e.g. Multiple instances of name="services[]"

I’m on my phone so I can’t type much but blank pages are due to php fatal errors. Typically these are syntax errors, calling functions/methods that don’t exist, etc.

You can set php logging to print out fatal errors instead of just a blank page. I don’t remember the syntax off the top of my head.

In my observatin the most common reason for a blank page is that the script is missing a character. If you left out a ' or } or ; somewhere, your PHP won't work. You don't get an error; you just get a blank screen.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.