Okay I'm quite new to php and mysql and I can't seem to figure this out. So what I'm trying to do is send some variables to a MySQL table. I have set up the connection inside a function (I believe this is possible(?) )
And with my current code it gives me the following error.
Notice: No database selected in INSERT INTO retrieveddata (profileId, profileName, pageViews, profileRevenue, currentDate) VALUES(NULL,'www.mywebsite.nl[testview2]', '48702', '0.0',NULL) in C:\xampp\htdocs\analyticsoverview\HelloAnalyticsApi.php on line 281
I have tried adding the select_db to my code but it doesn't work. This is my code.
function printResults(&$results) {
if (count($results->getRows()) > 0) {
$profileName = $results->getProfileInfo()->getProfileName();
$rows = $results->getRows();
$sessions = $rows[0][0];
$pageviews = $rows[0][1];
$bounces = $rows [0][2];
$betaalgoal = $rows [0][3];
$transrevenue = $rows [0][4];
// set up database connection
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "googleanalytics";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// select database that needs to be filled with the data from the variables
$conn->select_db('googleanalytics');
// the mysql query to insert the variables into table called retrieveddata
<
$query = "INSERT INTO retrieveddata (profileId, profileName, pageViews, profileRevenue, currentDate)
VALUES(NULL,'$profileName', '$pageviews', '$transrevenue',NULL)";
mysql_query($query) or trigger_error(mysql_error()." in ".$query);