redo php
REDO PHP
why
Could do nothing in hackerSon in ceress.
abstract
xampp
,post
,get
,
conn
,sql
,result
,
mysqli_query()
,
mysqli_fetch_assoc()
,
exe
open OSX-Manager.app
in /App/XMAPP/
o /Applications/XAMPP/manager-osx.app
Open localhost/
by browser
like this:
!(https://i.stack.imgur.com/OCBrm.png)
min
Go to App.../xampp/htdocs/
Then make echo.php
The inside
<?php echo "HELLO";
And access to localhost/echo.php
to see the result of hello.
POST and GET
GET
Write this and press the btn.
<form method="GET"> <input type="hidden" name="name" value="Daniel" > <button type = 'submit'>PRESS ME</button> </form>
then url changes from
http://localhost/postget.php
to
http://localhost/postget.php?name=value
This is GET
method.
POST
When using POST
instead of GET the code above,
The URL does not change.
But print $_POST
by echo in php like this:
echo $_POST['name'];
you see the name value Daniel
above the btn.
Echoing GET
by echo $_GET['name'];
and send name by GET method also returns Dan
conclude
submit by method='post'
:
$_POST['name']
gain the name's value.
'get',$_GET
are the same.
DB
Make a db
login MySQL by mysql -u root
and make a db like this:
CREATE DATABASE hoge;
CREATE TABLE tableName ( id int(11) auto_increment primary key not null, name VARCHAR(256) NOT NULL, price INTEGER , date DATE , PRIMARY KEY (id) );
insert records like this:
INSERT INTO tableName (name, price, column3, ...) VALUES (value1, value2, value3, ...);
print the records
make connecting php file:
includes/dbh.inc.php
and write:
$dbServername = "localhost"; $dbUsername = "root"; $dbPassword = ""; $dbName = "loginsystem"; $conn = mysqli_connect( $dbServername, $dbUsername, $dbPassword, $dbName );
Then write printing php:
conn.php
:
include_once 'includes/dbh.inc.php';
This first. this make connection.
Next, make sql:
$sql = 'select * from users;';
Then, result:
$result = mysqli_query($conn, $sql);
This $conn
is connection written in
includes/dbh.inc.php
Finally, print them from $result
by:
while($row = mysqli_fetch_assoc($result)) { echo $row['name']."<br>"; }
conclude
writing connection file and extend that by
include_once 'includes/dbh.inc.php';
Then make sql var:
$sql = 'select * from users;';
And result:
$result = mysqli_query($conn, $sql);
Finally, take that out from $result:
while($row = mysqli_fetch_assoc($result)) { echo $row['name']."<br>"; }
Then this can print every name inside the db.
Refered
https://www.youtube.com/playlist ?list=PL0eyrZgxdwhwBToawjm9faF1ixePexft-