php form is not updating database in mySQL -


i have created table display top 10 high scores game users. trying create form allows user enter new high score in form, hit submit, database updated , new leaderboard newly entered high score displayed. when go change high score database isnt updated , table doesnt change. frustraiting me , if knows why happening , give advice great. code below/

<?php  class databasemanager     {         private $servername = "localhost";         private $username = "root";         private $password = "";         private $dbname = "sokodatabase";         private $dbc;          function __construct() {             $this->dbc = mysqli_connect($this->servername, $this->username, $this->password, $this->dbname);         }          function __destruct() {             mysqli_close($this->dbc);         }          public function selecthighscores(){             // create query database             $query = "                     select username, highscores, rankno                     users, leaderboardhighscores                     users.id = leaderboardhighscores.userid                     order highscores desc                     limit 10";              // response database sending connection             // , query             $response = @mysqli_query($this->dbc, $query);              // if query executed proceed             if($response){                 echo '<table>                 <tr><td><b>rank</b></td>                 <td><b>username</b></td>                 <td><b>high score</b></td></tr>';                   // mysqli_fetch_array return row of data query                 // until no further data available                 while($row = mysqli_fetch_array($response)){                     echo '<tr><td>' .                     $row['rankno'] . '</td><td>' .                     $row['username'] . '</td><td>' .                     $row['highscores'] . '</td><td>';                      echo '</tr>';                 }                  echo '</table>';             } else {                 echo "couldn't issue database query<br />";             }         }     } ?>     

my html php create form...

                <div class = "leaderboard">                         <?php      // connection database      require_once('../sokodatabase.php');     $manager = new databasemanager;     $manager->selecthighscores();       //if(isset($_post['submit'])){            //require_once('../sokodatabase.php');               if ($_server['request_method'] === 'post') {                     $query = "                     update leaderboardhighscores                     set highscores=".$_post["highscores"].", rankno=".$_post["rankno"]."                     userid=".$_post["userid"];                  //var_dump($_post);                  //echo $query;                  @mysqli_query($this, $query);             }     //}              ?>      <form method="post" action="highscores.php">         high score <input type="text" name="highscores"/>         rankno <input type="text" name="rankno"/>         userid <input type="text" name="userid"/>         <input type="submit" value="submit">     </form>                 </div> 

first off, security measures, always sanitize user input before using in query.

second, don't need @ before mysqli_query - unless trying suppress , erorrs/warnings thrown function.

third, try , use same cases sql; used leaderboardhighscores in class, , leaderboardhighscores in second part of code; don't know one's real name in database assume former since working say. i'm saying because case-sensitivity result issue, please read mysql docs on matter.

fourth, using $this outside of class on page has no meaning (if not another).

add function databasemanager class:

public function sethighscores($uid, $score, $rank) {     $uid   = mysql_real_escape_string($uid);     $score = mysql_real_escape_string($score);     $rank  = mysql_real_escape_string($rank);      $query = "update leaderboardhighscores set highscores='{$score}', rankno='{$rank}' userid='{$uid}';";      return mysqli_query($this->dbc, $query); } 

and go on page:

if ($_server['request_method'] === 'post') {     $manager->sethighscores($_post['userid'], $_post['highscores'], $_post['rankno']); } 

also, should pdo_mysql, better option go for, understand you're doing learning basics guess.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -