I've created forms in php and want to update the data in the sql server database.
Following is my ad.php file.
<html>
<title>FORM</title>
<body><br><br>
<form action ="db_connection.php" method="post">
Activity:<input type="text" name="name"><br><br>
Units: <input id="number"><br><br>
<input type="submit" value="submit">
</form>
The data inserted in the above form should be updated in the table 'ad' of the database.
Following is my db_connection.php file:
<?php
class DB{
protected static $db;
const SERVER = "";
const SCHEMA = "";
const USER = "";
const PASS = "";
/*
* Sets up the database connection
* @return the database instance
*/
public static function databaseConnection(){
if(!self::$db){
try {
$databse = "sqlsrv:server=" . self::SERVER . ";Database=" . self::SCHEMA;
self::$db = new PDO($databse, DB::USER, DB::PASS);
self::$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
} catch(PDOException $e){
die("Error " . $e->getMessage());
}
}
return self::$db;
}
}
class ad{
public function dbAdmin(vat $Activity, int $Units): bool {
$conn = databaseConnection::getConnection();
$conn->beginTransaction();
$sql = "INSERT INTO ad('Activity', 'Units') VALUES (:Activity, :Units)";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':Units', $Units);
$stmt->bindParam(':Activity', $Activity);
if ($stmt->execute()) {
$conn->commit();
return true;
} else {
$conn->rollback();
return false;
}
}
}
I'm getting a blank page after submitting the form and the database is not updating with the new data being submitted. Can you please check the code and help me with the corrections.