0

I'd like to ask for help with connection/presentation of data from my database.

I have a hosted SQL database and Wordpress site, I successfully connected to my database via PHPMyAdmin, I have some content as for demonstration to try and display in list on one of the pages, I created an html block into which I typed this simple script to test connection,

<?php
$con = mysqli_connect("hostip", "username", "password", "databasename", port);
$sql = "SELECT * FROM stock_item;";
$result = mysqli_query($con,$sql);
$resultCheck = mysqli_num_rows($result);
if (0 < $resultCheck) {
while ($row = mysqli_fetch_assoc($result)){
echo $row['item_name'];
}
}
?>

but can not seem to get it to work(login details were provided by hosting provider). Any ideas or solutions please?

  • Check out how to see the error that `mysqli_query` is most likely throwing [here](https://stackoverflow.com/questions/17053466/how-to-display-errors-for-my-mysqli-query) If you are still stuck after seeing the error, feel free to hit us up again. – JNevill Aug 04 '21 at 15:51
  • hello, I added this line right after `$result = mysqli_query($con,$sql);` so now it is: `$result = mysqli_query($con,$sql) or trigger_error("Query Failed! SQL: $sql - Error: ".mysqli_error($con), E_USER_ERROR);`, but I do not see any error message/code on my page. – MarkTheBeat Aug 04 '21 at 16:26
  • I managed to solve the problem by putting the php into a shortcode and using the shortcode on my page, no idea why but oh well. – MarkTheBeat Aug 04 '21 at 16:33

0 Answers0