Hi,
It seems every one is so busy these days that no one has time to give a helping hand!
I am trying to work with MySQL from within a Page of WordPress but so far not successful. Although I can create a link inside the page and call a php file and then that php file takes over and every thing works fine. This means I can even work with MySQL as well. I have done this.
But what I really want is how to use the same working php code inside the wordpress page. I have tried couple of plugins. Such as (insert PHP) for insert the php code within the wordpress page but this again does not allow to work with MySQL. Tried even inserting the code inside a template page but even then it does not work.
Tried and created a simple plugin and used the same code inside that plugin of my own but the issue remains the same. The database connection does not materialize.
Please HELP!!!
Here is the code I am using:
<?php
DEFINE (‘DB_USER’, ‘root22’);
DEFINE (‘DB_PASSWORD’, ”);
DEFINE (‘DB_HOST’, ‘localhost’);
DEFINE (‘DB_NAME’, ‘sitename’);
$dbc = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die (‘Could not connect to MySQL: ‘ . mysqli_connect_error() );
mysqli_set_charset($dbc, ‘utf8’);
echo ‘<h1>Registered Users</h1>’;
$q = “SELECT CONCAT(last_name, ‘, ‘, first_name) AS name, DATE_FORMAT(registration_date, ‘%M %d, %Y’) AS dr FROM users ORDER BY registration_date ASC”;
$r = @mysqli_query ($dbc, $q); // Run the query.
$num = mysqli_num_rows($r);
if ($num > 0) {
echo “<p>There are currently $num registered users.</p>\n”;
echo ‘<table align=”center” cellspacing=”3″ cellpadding=”3″ width=”75%”>
<tr><td align=”left”><b>Name</b></td><td align=”left”><b>Date Registered</b></td></tr>’;
while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
echo ‘<tr><td align=”left”>’ . $row[‘name’] . ‘</td><td align=”left”>’ . $row[‘dr’] . ‘</td></tr>’;
}
echo ‘</table>’;
mysqli_free_result ($r);
} else {
echo ‘<p>There are currently no registered users.</p>’;
}
mysqli_close($dbc);
?>