Skip to main content

How to make a signup page using php programming language

After developing your application, it's time to setup a signup page where user can fill a form and submit before they will have access to protected website.

Test connection as a mysql user of database

First, Let's assume you have access to mysql database. we will test connection to database, once we can connect to database, we are good to go. If you look at our code below it's almost already made you can just copy and paste and start testing. Save it as dbconnect.php and run it.

<!--php $servername = "localhost"; $username = "webdesign"; $password = "web@design&33"; // Create connection $conn = new mysqli($servername, $username, $password); // Check connection if ($conn--->connect_error) { die("Connection failed: " . $conn->connect_error); } echo "Connection was successful!"; ?>

Create a new database where we can run testing

In below code, our code has been written in place you can copy and paste and start testing. The below code will help us create database with name 'webdesign' after running that code we will have good ready for use database. Save the code as dbcreate.php and run it.

<!--php $servername = "localhost"; $username = "webdesign"; $password = "web@design&33"; // Create connection $conn = new mysqli($servername, $username, $password); // Check connection if ($conn--->connect_error) { die("Connection failed: " . $conn->connect_error); } // Create database $sql = "CREATE DATABASE webdesign"; if ($conn->query($sql) === TRUE) { echo "Database webdesign created successfully"; } else { echo "Error creating database: " . $conn->error; } $conn->close(); ?>

Creating table in database we created earlier

In previous database we created, now let's create table where we will store user profiles. The code below has been written and ready for testing. You can write it manually or copy and paste. Copy, paste and save the code as createtabele.php. Now, if you run the below code this will create table with name 'profiles' for you.

<!--php $servername = "localhost"; $username = "webdesign"; $password = "web@design&33"; $dbname = "webdesign"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn--->connect_error) { die("Connection failed: " . $conn->connect_error); } // sql to create table $sql = "CREATE TABLE profiles ( id INT(7) UNSIGNED AUTO_INCREMENT PRIMARY KEY, image VARCHAR(255) NOT NULL, fullname VARCHAR(255) NOT NULL, fulladdress VARCHAR(255) NOT NULL, emailaddress VARCHAR(255) NOT NULL, phonenumber VARCHAR(255) NOT NULL, username VARCHAR(255) NOT NULL, password VARCHAR(255) NOT NULL, project VARCHAR(255) NOT NULL, subscription VARCHAR(255) NOT NULL, gender VARCHAR(255) NOT NULL, reg_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP )"; if ($conn->query($sql) === TRUE) { echo "Table profiles created successfully"; } else { echo "Error creating table: " . $conn->error; } $conn->close(); ?>

The HTML page for our signup ready for testing

The html tag below has been fully packaged, you can write it manually or copy and paste to your html document after pasting, remember to save it as signup.php and run it to see the output of a cool structured signup page ready for user input.

<form method="POST" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" enctype="multipart/form-data"> <fieldset style="border-radius:5px;"> <legend>Register your profile today</legend> <label>Select profile picture</label><br> <input type="file" name="file" id="image" style="width:100%; padding:15px; border:none; display:block; font-size:18px; border-radius:5px;" value=""><br> <label>Full name</label><br> <input type="text" name="fullname" id="fullname" style="width:100%; padding:15px; border:none; display:block; font-size:18px; border-radius:5px;" value=""><br> <label>Full address</label><br> <textarea name="fulladdress" id="fulladdress" rows="5" cols="5" style="width:100%; padding:15px; border:none; display:block; font-size:18px; border-radius:5px;" value="">Your community, local government and state</textarea><br> <label>Email address</label><br> <input type="email" name="emailaddress" id="emailaddress" style="width:100%; padding:15px; border:none; display:block; font-size:18px; border-radius:5px;" value=""><br> <label>Phone number</label><br> <input type="number" name="phonenumber" id="phonenumber" style="width:100%; padding:15px; border:none; display:block; font-size:18px; border-radius:5px;" value=""><br> <label>Username</label><br> <input type="text" name="username" id="username" style="width:100%; padding:15px; border:none; display:block; font-size:18px; border-radius:5px;" value=""><br> <label>Password</label><br> <input type="password" name="password" id="password" style="width:100%; padding:15px; border:none; display:block; font-size:18px; border-radius:5px;" value=""><br> <label>Select project type</label> <select name="project" style="width:100%; display:block; border:none; border-radius:5px; font-size:18px; margin-bottom:15px; padding:15px;"> <option>Select project type</option> <option value="Web technology developer">Web technology developer</option> <option value="Server-side technology developer">Server-side technology developer</option> <option value="Database management developer">Database management developer</option> <option value="Local and public network developer">Local and public network developer</option> </select> <input type="hidden" name="subscription" id="subscription" value="0.00"> <label>Gender</label> <input type="radio" name="radio" id="radiobuttonone" style="width:; padding:0; border:none; display:inline-block; font-size:18px; border-radius:0;" value="Male">Male <input type="radio" name="radio" id="radiobuttontwo" style="width:; padding:0; border:none; display:inline-block; font-size:18px; border-radius:0;" value="Female">Female</br> <p><input type="hidden" name="success" value="success"></p> <input type="submit" name="submitData" value="Register" style="margin-top:15px; padding:15px; width:45%; float:left; cursor:pointer; color:white; display:block; background:#04AA6D; border:none; font-size:18px; border-radius:5px;"> <input type="reset" onclick="window.location='index.php'" value="Cancel" style="margin-top:15px; padding:15px; width:45%; float:right; cursor:pointer; color:white; display:block; background:#04AA6D; border:none; font-size:18px; border-radius:5px;"> </fieldset> </form>

The php script for users so they can submit their details to our database

In our script below, we have prepared a cool php script to submit user profiles to the database, the details include: (image, fullname, fulladdress, emailaddress, phonenumber, username, password, project, subscription, gender) it's super cool you can copy and paste, but remember to paste on top of your html file and save it as signup.php and run it. Also remember to create a folder where the profile picture will be store, such as C:\xampp\htdocs\image then start filling the form, after filling the form just click "Submit", if everything goes well you won't see error messages from php, but if there is you must see atleast one.

<!--php $servername = "localhost"; $username = "webdesign"; $password = "web@design&33"; $dbname = "webdesign"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn--->connect_error) { die("Connection failed: " . $conn->connect_error); } //Submit data if (isset($_POST["submitData"])) { $folder = "image/"; $image = $folder.basename($_FILES["file"]["name"]); if(empty($_POST["fullname"])) { echo "<script>alert('Please enter your full name.');</script>"; exit; }else{ $fullname = $_POST["fullname"]; } if(empty($_POST["fulladdress"])) { echo "<script>alert('Please enter your full address.');</script>"; exit; }else{ $fulladdress = $_POST["fulladdress"]; } if(empty($_POST["emailaddress"])) { echo "<script>alert('Please enter your email address.');</script>"; exit; }else{ $emailaddress = $_POST["emailaddress"]; } if(empty($_POST["phonenumber"])) { echo "<script>alert('Please enter your phonenumber.');</script>"; exit; }else{ $phonenumber = $_POST["phonenumber"]; } if(empty($_POST["username"])) { echo "<script>alert('Please enter your username.');</script>"; exit; }else{ $username = $_POST["username"]; } if(empty($_POST["password"])) { echo "<script>alert('Please enter your password.');</script>"; exit; }else{ $password = $_POST["password"]; } if(empty($_POST["project"])) { echo "<script>alert('Please select your project.');</script>"; exit; }else{ $project = $_POST["project"]; } if(empty($_POST["subscription"])) { echo "<script>alert('Please select your subscription.');</script>"; exit; }else{ $subscription = $_POST["subscription"]; } if(empty($_POST["radio"])) { echo "<script>alert('Please select your gender.');</script>"; exit; }else{ $gender = $_POST["radio"]; } $stmt = $conn->prepare("INSERT INTO profiles (image, fullname, fulladdress, emailaddress, phonenumber, username, password, project, subscription, gender) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); $stmt->bind_param("ssssssssss", $image, $fullname, $fulladdress, $phonenumber, $emailaddress, $username, $password, $project, $subscription, $gender); $stmt->execute(); $stmt->close(); if (move_uploaded_file($_FILES["file"]["tmp_name"], $image)) { echo "<script>alert('Your registration was successful.\nWe will get back to you shortly.');</script>"; } } $conn->close(); ?>

Testing our signup page now

In the above code, point your browser to http://localhost/signup.php fill that form correctly and submit, you will see a success messages indicating that the registration was successful.

Let's view the details we submitted to the server. Now, copy the code below, paste and save it as profile.php point your browser to the file: http://localhost/profile.php and run it. This will retrieve our profile details. If you have written all the above code correctly I think it's error free, but if the above code spot error don't hesitate to get in touch so that we can review the code.

<!--php $servername = "localhost"; $username = "webdesign"; $password = "web@design&33"; $dbname = "webdesign"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn--->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "SELECT * FROM profiles"; $result = $conn->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { echo '<p>'.$row["id"].'</p>'; ?> <p><img alt="Image" loading="lazy" src="&lt;?php echo $row[&#39;image&#39;]; ?&gt;" width="200"></p> <!--php echo '<h2-->'.$row["fullname"].'</h2>'; echo '<p>'.$row["fulladdress"].'</p>'; echo '<p>'.$row["emailaddress"].'</p>'; echo '<p>'.$row["phonenumber"].'</p>'; echo '<p>'.$row["username"].'</p>'; echo '<p>'.$row["password"].'</p>'; echo '<p>'.$row["project"].'</p>'; echo '<p>'.$row["subscription"].'</p>'; echo '<p>'.$row["gender"].'</p>'; echo '<p>'.$row["reg_date"].'</p>'; } } else { echo "0 results"; } $conn->close(); ?>

Summary

If you have followed the above tutorials carefully, you will make a good signup page. Although not the best signup page in the world, but a good signup page that will earn you a good level as application developer. Thanks for reading this article. if you have a question submit them on commentbox. Thank you.

Comments

Latest post

We will take a closer look on how to bind webpage in python programming language

Today we will take a closer look on how to run python in your webpage under windows operating system. Let's assume you have installed xampp in your windows operating system and have python program installed as well. If you have not done so, then go on to installed xampp in your computer together with python program. Remember to select software version compactible to your computer. When you are ready with these two software, then copy the code below: #!"C:\Users\Administrator\AppData\Local\Programs\Python\Python311-32\python.exe" print ("Content-Type: text/html\n") print (" ") print (" ") print (" ") print (" ") print (" Hello world! ") print (" Welcome to my first python webpage ") print (" ") print (" ") Save the above code as index.py in C:\xampp\htdocs the path should be: C:\xampp\htdocs\index.py On your browser address bar you can type http://localhost/index.py, ...

Our today post will focus on how to implement php class and method

A class is a container for objects, and object is items in class. Class is container that we can store all kinds of obejects, such as variable, function etc. Today we will implement class and objects , property, set, get and the rest. If you look at the php class below, this is exactly how to declare empty php class. Php class container with public objects, function set parameters and gets parameters. In php class below, we created two functions, one to set a value and one to get the value, pass the instance object and its value. Now you can copy the below code for your testing. name = $name; } function getname() { return $this->name; } } $username = new KcFuns(); $username->setname('Kenan Chiquado'); echo "Output:"; echo "Username is: ".$username->getname(); echo "----------------------------------"; ?> Php class several objects function and parameters In our second php class implementation, we will lo...

Today we will look into how to implement cUrl in php application

Passing json file via cUrl in php We will implement passing json file via cUrl and submit to next server. cUrl is all about special communication between two or more server. Such as server1.com sending data to server2.com. A lot of beginner had always ask endless question about what is cUrl and what cUrl actually does. A simple answer there is: cUrl is a special communication between two or more server. Now, if you look at json code below, it has been neatly written and indented and ready for testing. Launch your notepad copy the json data below and save it as data.json place it in a folder where you saved other php file. { "id": "1", "image": "image\/chiquado.jpg", "fullname": "Kenan Chiquado", "fulladdress": "Udah, Igbo-eze North LGA, Enugu state, Nigeria", "emailaddress": "2348130802790", "phonenumber": "presschiquado@gmail.com...

Our today post will focus on how to implement php hits counter

PHP counter step 1: Have you ever wonder how you can monitor, view or learn how many times your website is been processed by visitors. How many times your website is been browse by your visitors? If your answer is 'no', then it's time to learn all these. You can learn how many times browser processed your website by binding certain php script on top of your webpage. Now, if you look at our php script below, this script will help you count how many times your website was processed at any given moment. To apply our php script below, you can copy and paste this script on top of your webpage before html declaration. PHP counter step 2: Again, the below script, you can copy and put it in a separate file. All you need to do is check time to time and see the digits number your script return. That's exactly how many times your website was processed. Example of the counter: Hits counter While applying our tutorials, if our code spot error, don't hesit...

In today post we will focus on how to create php script that could upload picture to server

Before writing script to upload files to server, you have to check ensure that php file upload is set to 'On' in php.ini. Open C:\xampp\php\php.ini file locate the line that says upload_file = On and also change the php upload max setting, example: php_max_upload = 100m. Now save the file, restart the server and start writing php script to upload your file. Step 1: Below is the html code to implement our practice of file upload. You can write it manually or copy and paste. " enctype="multipart/form-data" method="POST"> Uploader Step 2: Php command to target the upload folder, php comman to get file name, php command to check upload status, and php command to validate file extension. Below is our sample code: Step 3: We will use php global object called $_POST to get the image object. And check if the file is image or not, if it's not image the upload status will be set to zero. Below is our sample code: if(isset(...