Help with querying MySQL database

Here’s my files so far. I’ve changed them a bit and tried a few things with still no results. I think it’s something really simple that I’m missing but I just can’t work it out. Getting data from a database to display in hype is a lot harder than I expected especially as sending data to the database was pretty simple.

data recieve from (41.5 KB)

If anyone has any solutions then I’ll be really grateful.



The zip doesn’t seem to extract for me; can you try again/a different method?

1 Like

Hi @Jonathan

I’ve loaded both files onto drop box and created 2 share links:

The PHP file:

The HYPE file:

Hope this works and thanks again,


hi! i got success with this php and hype in (104,1 KB)

1 Like

hi @strmiska

have you created that on hype 4.0? I’m unable to open it on 3.6.7 as it’s saying it was created in a newer version.



sorry, ialways forget, that documents aere autosaved in newest versions. (104,5 KB)

1 Like

Thanks for this! I’ll have a play around with it to see if I can get this working on my server and then attempt to use the code for my project :slight_smile:

1 Like

great! i use it for creating a score- list automatically after finishing a game.
it´s working really cool.

1 Like


When sending an Ajax request as dataType: JSON you’ll have to return (or echo out) the response as JSON as well so in your PHP file you should be using json_encode($variable) that way your AJAX success property (function) will contain the echo’d content.

There are inherent problems in my opinion though as you’re echoing out HTML too and aren’t really dealing with arrays / objects of information so JSON may not be the best in this case. Maybe look into using the dataType: HTML with AJAX.

1 Like

I’m planing to use it to inform people of the last used site on the body where insulin was administered to make sure they choose a different site the next time. This is why I need data from a data base to be displayed. I’ve already created a system to send the information to the database so this should help complete the next steps of the idea development. Long way to go though!

Thanks @DBear I’ll look further into this :slight_smile:

Hi @strmiska

I’ve managed to get your example working perfectly. I was just wondering if you had managed to get more than one row of data to be received from the database to display in hype?

for example using the PHP:

$sql="SELECT * FROM $tableName WHERE id = 3 AND id = 2";

isn´t it possible using this?

$sql = "SELECT * FROM $tableName";

then you have to create a table in innerHTML of an rectangle to display the whole sql
EDIT: if you want specifical rows only - this example i never tried, sorry.
for this i´ve to test, but haven´t time yet

Ideally I need to each part of the data to be in its own innerHTML so I can use it in hype to trigger other javascript events

that´s tricky, but for this i´m not the right person. i´ve to make tests, but time is missing at this moment

No problem and thanks for your help. I’m currently exploring if MySQL can send only the data that I need as well but I’m not sure how it all works just yet.

1 Like

@DBear is genius in this - he helped me out a lot :sunglasses:
maby he can help you , too

Regards Chris
Your query has been very educational, I am starting in Hype, thanks to your question I have been able to visualize Mysql data.
You have commented that you have sent information to the database, it would be possible for you to share it with me on file to learn from your experience.

I appreciate your support on the matter. :grinning:

Hi Idiaz,

Thanks for your message.

I have these code snippets you can use that I edit every time I want to achieve sending information to mysql. I sure someone on here will be able to improve but it's a starting point for you.

The information I send to my database in this example is date, time, record, size and resultsend. Your mySQL database must match the data you're sending to it so change these parts as needed.

First place this code in a a function on hype:

// element - DOMHTMLElement that triggered this function being called
// event - event that triggered this function being called
function resultsend(hypeDocument, element, event) {
    url: 'resultsend.php',
    type: 'POST',
    dataType: 'JSON',
    data: {
          date: $('#date').text(),
          time: $('#time').text(),
          record: $('#record').text(),
          size: $('#size').text(),
          resultsend: $('#resultsend').text(),
// I never managed to get the success function to work. Maybe someone reading this could improve on this part?
   success: function (res) {


// I go to another scene on my project once data has been attempted to be sent. Delete if not needed. (if you manage to get the success function to work you may be able to change something on the scene to show its successfully sent).
hypeDocument.showNextScene(hypeDocument.kSceneTransitionInstant, 1.1);
} else {

// I use a scene to test my internet connection. Delete if not needed. This was only included as I couldn't get the success function to work. 

hypeDocument.showSceneNamed('connection', hypeDocument.kSceneTransitionInstant, 1.1)


Then create a .php file called resultsend.php and include the following


     // get values form input text and number

$date = $_POST['date'];
$time = $_POST['time'];
$record = $_POST['record'];
$size = $_POST['size'];
$resultsend = $_POST['resultsend'];

    // connect to mysql database using mysqli

$connect = mysqli_connect($hostname, $username, $password, $databaseName);
    // mysql query to insert data

$query = "INSERT INTO `$resultsend`(`date`, `time`, `record`, `size`) VALUES ('$date','$time','$record','$size')";

$result = mysqli_query($connect,$query);


You should have a config.php which includes your mySQL database hostname, username, password and database name.

If anyone can improve on this method please contribute. I'm sure there more secure ways to do all of this.

Let me know how you get on,


1 Like

5 posts were merged into an existing topic: Save Data PHP MySQL