0% found this document useful (0 votes)
20 views1 page

Documento

This document provides sample PHP code to connect to a MySQL database, select a database, check if a record exists, and output the record's field value. The code connects to the database, selects a database, runs a query to check for a record, and outputs the field value if a record is found.

Uploaded by

Carlos Mendes Jr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views1 page

Documento

This document provides sample PHP code to connect to a MySQL database, select a database, check if a record exists, and output the record's field value. The code connects to the database, selects a database, runs a query to check for a record, and outputs the field value if a record is found.

Uploaded by

Carlos Mendes Jr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

?

php

//Sample Database Connection Syntax for PHP and MySQL.

//Connect To Database

$hostname=”your_hostname”;

$username=”your_dbusername”;

$password=”your_dbpassword”;

$dbname=”your_dbusername”;

$usertable=”your_tablename”;

$yourfield = “your_field”;

Mysqli_connect($hostname,$username, $password) or die (“html>script


language=’JavaScript’>alert(‘Unable to connect to database! Please try again
later.’),history.go(-1)/script>/html>”);

Mysqli_select_db($dbname);

# Check If Record Exists

$query = “SELECT * FROM $usertable”;

$result = mysqli_query($query);

If($result){

While($row = mysqli_fetch_array($result)){

$name = $row[“$yourfield”];

Echo “Name: “.$name.”br/>”;

?>

You might also like