This assignment will assess the competency 3 Construct advan

This assignment will assess the competency 3. Construct advanced SQL queries.

Directions: Using your account at 000WebHost and PHPMyAdmin, create a PHP pages that

Display data from your database.

Add records to your database.

Include the URLs for your instructor.

Install PHPMyEdit from PHPMyEdit.org.

Create a data view using the software and your dataset.

.

Solution

Solution:

<?php
$servername = \"localhost\";
$username = \"username\";
$password = \"password\";
$dbname = \"myDB\";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die(\"Connection failed: \" . $conn->connect_error);
}

$sql = \"SELECT id, firstname, lastname FROM MyGuests\";


$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo \"id: \" . $row[\"id\"]. \" - Name: \" . $row[\"firstname\"]. \" \" . $row[\"lastname\"]. \"<br>\";
    }
} else {
    echo \"0 results\";
}
$conn->close();
?>

//using the sample script above you should be able to select and view data from database.

//the following script should help you know how you can add records into a database table

<?php
$servername = \"localhost\";
$username = \"username\";
$password = \"password\";
$dbname = \"myDB\";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die(\"Connection failed: \" . $conn->connect_error);
}

$sql = \"INSERT INTO MyGuests (firstname, lastname, email)
VALUES (\'John\', \'Doe\', \'..n@example.com\')\";

if ($conn->query($sql) === TRUE) {
    echo \"New record created successfully\";
} else {
    echo \"Error: \" . $sql . \"<br>\" . $conn->error;
}

$conn->close();
?>

This assignment will assess the competency 3. Construct advanced SQL queries. Directions: Using your account at 000WebHost and PHPMyAdmin, create a PHP pages th
This assignment will assess the competency 3. Construct advanced SQL queries. Directions: Using your account at 000WebHost and PHPMyAdmin, create a PHP pages th

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site