I've tried the following code, which executes without error, but yet I see nothing in phpMyAdmin to reflect the inserted data:
is this code correct, or should this be done differently?
Code:
<?php // Require files for server-side includes for fpdf library, functions script, and database connection info. require $_SERVER['DOCUMENT_ROOT']."/scripts/fpdf/fpdf.php"; require $_SERVER['DOCUMENT_ROOT']."/scripts/functions.php"; require $_SERVER['DOCUMENT_ROOT']."/scripts/connect.php"; //dbinfo is a function defined in functions.php which returns the database connection varriables // for $host, $user, $pass, and $dbname. dbinfo(); //Connect to database. $con = mysqli_connect($host, $user, $pass, $dbname); //check for database connection errors. if ( mysqli_connect_errno()) { die('Failed to connect to SQL:' . mysqli_connect_error()); } //Set PHP vars to write to database. $postusername = 'testusername'; $postip = getIP(); $postdate = '02/27/21'; $dbfilename = 'test.pdf'; $mime = 'pdf'; $pdffile = fopen($_SERVER['DOCUMENT_ROOT']."/pdf/file.pdf", "rb"); $postcomments = 'insert comments here'; //Prepare and Execute SQL statement. $stmt = $con->prepare('INSERT INTO pdf (username, ip, date, filename, mime,file, comments) VALUES (?, ?, ?, ?, ?, ?, ?)'); $stmt->bind_param("sssssbs", $postusername, $postip, $postdate, $dbfilename, $mime, $pdffile, $comments); $stmt->execute(); //Close Database connection. $stmt->close(); $con->close(); // Give Feedback to User and Exit this script. echo 'write to database sucessful'; exit; ?>
Comment