Making a user profile in php is as basic as bubbling water, in the event that you know how to switch on the socket, this tutorial is requested by a dear companion of mine.
Has he would be kicking off his first php to mysqli database interaction, I do jump at the chance to surrender a head up.
Okay, these are things to consider while making a user profile, for example like facebook or other social platforms, this worked for them, so we are to utilize this same rationale on this tutorial call PHP Conditional Statements.
Very often when you code, you want to perform different actions for different conditions. You can use conditional statements in your code to do this.
In PHP we have the accompanying restrictive articulations:
· If statement - executes some code in the event that one condition is valid
· if...else explanation - executes some code if a condition is valid and another code if that condition is false
· if...elseif....else proclamation - executes diverse codes for more than two conditions
· switch articulation - chooses one of many pieces of code to be executed.
\
PHP - The if Statement
The if statement executes some code in the event that one condition is valid.
Syntax
<?php $d = date("D"); if($d == "Thurs"){ echo "Approaching to a weekend!"; } ?>
The following example will output "Approaching to a weekend!" if the current day is Thursday:
Database Schema
-- -- Table structure for table `users` -- CREATE TABLE IF NOT EXISTS `users` ( `uid` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(20) NOT NULL, `password` varchar(100) NOT NULL, `created` int(11) NOT NULL, PRIMARY KEY (`uid`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=15 ;
Connection to Database config.php
<?php define("DBHOST", "localhost"); //host name or 127.0.0.1 define("DBNAME", "phptest"); // database name define("DBUSER", "root"); // dtabase username define("DBPASS", ""); // database password empty always localhost //Connect and select the database $db = new mysqli(DBHOST, DBUSER, DBPASS, DBNAME); // create new object(instances) for connection if ($db->connect_error) { // check for database error die("Connection failed: " . $db->connect_error); // displace error message } else { //echo 'database connection is successful!'; // don't edit this else your app won't work } ?>
HTML Code for Creating User Profile
<form class="form-inline" action="#" method="POST"> <input type="text" name="username" SIZE="50" required placeholder="choose username">
<input type="password" name="password" SIZE="50" required placeholder="choose password"><button type="submit" name="reg">Create Account</button> ; </form>
PHP Code for Creating User Profile
<?php require 'config.php'; // db connectio file ######################### signup script ######################### if(isset($_POST['reg'])) // if the user click on signup bottom { // open if $username=$_POST['username']; // get user name from input and assign to user name variable $password=md5($_POST['password']); // get user password from input and assign to password variable $insertdetails=$db->query("INSERT INTO users (username, password, created) VALUES('".$username."', '".$password."', NOW()) "); // insert username and password into users table in phptest database //NOTE: NOW() will get the corrent timestamp if($insertdetails) // if return 1 which is success { // open if echo "successful!"; // echo success message to user } //close if else{ // open else // or display error message to user echo "Oops! error occured, register again!"; } // close else } // close if ############################# end here #######################################
Subscribe or say hello to me below
Hit me with a comment!