How to build form in PHP

in #utopian-io6 years ago

()
Hello today i show you how to build simple form in php.
But first you must have apache i purpose XAMPP simple fastest and ease local server for Windows, Ubuntu and Mac.
The next you must have Editor i using Visual Studio Code becouse its free and very good for work he's fastest like in brackets.

Step one create in htdocs folder and call him simple form.
Inside him make file index.php and style.css
basic structure html code look like this.

<form action="<?echo $_SERVER['PHP_SELF']; ?>" method="post">
    <label for="name">Your name</label>
    <input type="text" name="name" id="name">
    <label for="email">Your Email</label>
    <input type="email" name="email" id="email">
    <label for="password">Your Password</label>
    <input type="password" name="password" id="password">
    <input type="submit" value="Wyslij">
</form>

This is our simple form someone wie have action and methods.
Action its where i want send this form where file its can be login.php example or dashboard.html.
I using php method echo $_SERVER['PHP_SELF'] the action must be to this site in index.php the method wwe have to the one its a get its means you see what you write if you choosing get and send on link you can see your name email and password like you see its a dangarous becouse the client and hackers potential can whatch your password and using for self. The POST its protect your data and protect SQL INJECTION its means no one have acces to your data and data databse someone have thounds data of clients.
I skip what is inputs becouse you see on your site.
Now i show you code php.

if (isset($_POST['name'])) {
$name = $email = $password = "";

$name = htmlentities(trim($_POST['name']));
$email = htmlentities(trim($_POST['email']));
$password = sha1(htmlentities(trim($_POST['password'])));

}

//Our form up stairs.

<?
echo $name.'
';
echo $email.'
';
echo $password.'
';
?>

Ok but first checkout our if we have isset its a if our value exists in input the next its a $_POST['name'] we get value and send to our web or whatever you want to do it i show you what. How moore options can you do it.
The next we have our variables $name $email and $password. About $_POST i using trim sh1 and htmlentities.
trim() -> remove whitespace on start and ending.
sha1() -> secure your password on 160 bitów this its hashing your own password.
htmlentities() -> he change special type to sql example ' " / * #
and echo show our values full code you can read this http://sandbox.onlinephpfunctions.com/code/61413bdf0f8c3319a173c52c1c4ceb83021dd38d

Please for comments if like my blog suggest me or add your own options

Sort:  

I'm beginner please forgive me my language i started and i try motivation peaple to programming.

Coin Marketplace

STEEM 0.29
TRX 0.11
JST 0.033
BTC 63945.57
ETH 3135.76
USDT 1.00
SBD 4.00