I’ve never used PHP in my life and would love to learn PHP. I am a SQL guy who manages a few PostgreSQL database servers. I really am looking for a PHP template that I can throw into Apache which allows users to submit information and pump it to my database back-end. I honestly have no HTML / PHP experience what-so-ever and need anything that will allow users to hit a PHP site publicly and submit info via the PHP online form. Does anything like what I described above exist as a template I can use freely?
[php]
<?php if ($_POST['submit']){ //Connect to your database here -- usually in a separate file //PDO Connection $db_myHost = "localhost"; $db_myUser = ""; $db_myPassword = ""; $db_myDatabase = ""; $dbconn = new PDO('mysql:host='.$db_myHost.';dbname='.$db_myDatabase, $db_myUser, $db_myPassword); try { $dbPDO = new PDO('mysql:host='.$db_myHost.';dbname='.$db_myDatabase, $db_myUser, $db_myPassword); $dbPDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { //echo "Error!: " . $e->getMessage() . " die(); } //Insert to your database here $statement = $dbconn->prepare("INSERT INTO users username, password VALUES (:username, :password); if ($statement->execute([ ":username" => $_POST['username']; ":password" => hash($_POST['password']); ])){ //Insert was successful $count = $statement->rowCount(); print("Inserted $count rows.\n"); }else { //There was a problem -- start debugging } ?> UsernamePassword
[/PHP]
Note the above works with PHP 5.4 and I haven’t tested it but it should work.
Thank you! I see ‘MySQL’ is listed in the form code. I would just change the MySQL connection string to a PostgreSQL connection string, correct?