11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

www.it-ebooks.infoCHAPTER 36 • INDEXES AND SEARCHINGListing 36-1. Searching the Employee Table (search.php)Search the employee database:Last name:// If the form has been submitted with a supplied last nameif (isset($_POST['lastname'])) {}// Connect to server and select database$db = new mysqli("localhost", "websiteuser", "secret", "chapter36");// Query the employees table$stmt = $db->prepare("SELECT firstname, lastname, email FROM employeesWHERE lastname=?");$stmt->bind_param('s', $_POST['lastname']);$stmt->execute();$stmt->store_result();// If records found, output themif ($stmt->num_rows > 0) {$stmt->bind_result($firstName, $lastName, $email);while ($stmt->fetch())printf("%s, %s (%s)", $lastName, $firstName, $email);} else {echo "No results found.";}703x

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!