Quantcast
Channel: Topic Tag: MySQL | WordPress.org
Viewing all articles
Browse latest Browse all 5527

pmarks906d on "Accessing MySql database from page function"

$
0
0

Hi, I think I have gotten on track.I found a solution on line. If I put a form on my theme page, and have the submit button post from the local machine to the server to another php file, the following MySql code works inside that file. I've still got to work on security, however the basics seems to be there:
<html>
<body>
Welcome <?php echo $_GET["name"]; ?>
Your email address is: <?php echo $_GET["email"]; ?>
<?php
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO myCustomers(firstname, lastname)
VALUES ('Fred', 'Marks')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "
" . $conn->error;
}
$conn->close();
?>
</body>
</html>


Viewing all articles
Browse latest Browse all 5527

Trending Articles