Hello i need to create a form that adds Data to a MySQL Database using PHP.
I created this, but it does not work
THIS NEEDS TO BE ADDED:
INSERT INTO `mailserver`.`virtual_users`
(`domain_id`, `password` , `email`)
VALUES
('5', ENCRYPT('newpassword', CONCAT('$6$', SUBSTRING(SHA(RAND()), -16))) , 'email3@newdomain.com');
It would be also nice that PHP queries the latest domain_id and adds a 1 after every new Email Address
<!DOCTYPE html>
<html>
<head>
<title>Add an E-Mail</title>
</head>
<body>
<?php
if(isset($_POST['submit'])){
$servername = "localhost";
$username = "lalalala";
$password = "heheheh";
$dbname = "mailserver";
try {
$userpassword = = $_POST['password'];
$useremail = = $_POST['email'];
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "
INSERT INTO `mailserver`.`virtual_users`
(`domain_id`, `password` , `email`)
VALUES
('3', ENCRYPT('$userpassword', CONCAT('$6$', SUBSTRING(SHA(RAND()), -16))) , '$useremail');
";
// use exec() because no results are returned
$conn->exec($sql);
echo "New record created successfully";
}
catch(PDOException $e)
{
echo $sql . "<br>" . $e->getMessage();
}
$conn = null;
}
?>
<form action="" method="post">
<p>Email<input type="email" name="email" placeholder="Your Email"></p>
<p><input type="password" name="password" placeholder="Your Password"></p>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.