PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
create table scientist (id integer, firstname varchar(100), lastname varchar(100), password varchar(8)); insert into scientist (id, firstname, lastname, password) values (1, 'albert', 'einstein', 'emc2'); insert into scientist (id, firstname, lastname, password) values (2, 'isaac', 'newton', 'force'); insert into scientist (id, firstname, lastname, password) values (3, 'marie', 'curie', 'glowin'); SELECT * FROM scientist
Copy Clear
Copy Format Clear
<?php $username = "albert"; $password = "1234"; $query = "SELECT * FROM scientist WHERE firstname = '" . $username . "' AND password = '" . $password . "'"; //printf('Query is: %s ' . PHP_EOL, $query); // Run query using mysqli $result = $mysqli->query($query); if(mysqli_num_rows($result) > 0 ) { list($id, $firstname, $lastname, $password) = mysqli_fetch_array($result); echo "successfully logged in ..."."\r\n"; echo "Welcome " . "$firstname $lastname"."\r\n"; } else { echo "wrong username or password"."\r\n"; } printf(PHP_EOL . PHP_EOL . '<DEBUG OUTPUT:>' . PHP_EOL); printf('Result is:' . PHP_EOL); $result = $mysqli->query($query); if (mysqli_num_rows($result) === 0) { printf('<nothing>' . PHP_EOL); } else { while (list($id, $firstname, $lastname, $password) = mysqli_fetch_array($result)) { echo "$firstname - $lastname - $password"."\r\n"; } } printf('</DEBUG OUTPUT:>' . PHP_EOL); ?>
Show:  
Copy Clear