How do I make this older version of php work in php7? I have a mysql database that I use for posting high scores from my games that I create in Construct 2. But now it has stopped working because my host updated to php7 ( at the moment I can choose between php 7.1 - 7.3 )
I have tried for a long time, searching the web, to make it work again, but haven't been able to solve it.
I have 2 php-files: getscores.php and savescores.php
When I try to view getscores.php in a webbrowser ( Chrome ) I get an error: Fatal error: Uncaught Error: Call to undefined function mysql_query() ...And it's referring to line 18.
I'm sorry but I have almost no knowledge of php and mysql-databases
Thank you so much, in advance, if there's anyone out there who could help. :) ///Soulmachine!
getscores.php
<?php
header('Access-Control-Allow-Origin: *');
$host="localhost"; // Host name
$username="username"; // Mysql username
$password="password"; // Mysql password
$db_name="database"; // Database name
$tbl_name="scores"; // Table name
// Connect to server and select database.
$link = mysqli_connect("$host", "$username", "$password", "$db_name");
// Retrieve data from database
$sql="SELECT * FROM scores ORDER BY score DESC LIMIT 10"; // The 'LIMIT 10' part will only read 10 scores. Feel free to change this value
$result=mysql_query($sql);
// Start looping rows in mysql database.
while($rows=mysqli_fetch_array($result)){
echo $rows['name'] . "|" . $rows['score'] . "|";
// close while loop
}
// close MySQL connection
mysql_close();
?>
savescores.php
<?php
$db = "database";//Your database name
$dbu = "username";//Your database username
$dbp = "password";//Your database users' password
$host = "localhost";//MySQL server - usually localhost
$dblink = mysqli_connect($host,$dbu,$dbp,$db);
if(isset($_GET['name']) && isset($_GET['score'])){
//Lightly sanitize the GET's to prevent SQL injections and possible XSS attacks
$name = strip_tags(mysql_real_escape_string($_GET['name']));
$score = strip_tags(mysql_real_escape_string($_GET['score']));
$sql = mysqli_query($dblink, "INSERT INTO `$db`.`scores` (`id`,`name`,`score`) VALUES ('','$name','$score');");
if($sql){
//The query returned true - now do whatever you like here.
echo 'Your score was saved. Congrats!';
}else{
//The query returned false - you might want to put some sort of error reporting here. Even logging the error to a text file is fine.
echo 'There was a problem saving your score. Please try again later.';
}
}else{
echo 'Your name or score wasnt passed in the request. Make sure you add ? name=NAME_HERE&score=1337 to the tags.';
}
mysqli_close($dblink);//Close off the MySQL connection to save resources.
?>