简体   繁体   中英

PHP isn't updating with the MYSQL database

The code below shows my connection to reach my MYSQL Database, but for some reason once it grabs the details from the database it doesn't update the PHP page after that. As an example, currently the table lastWinner is a string datatype which contains "David". After saving the php file the output shows as David, but if I change the value in the mysql database the output doesn't change afterwards.

  <div id="navigation">
     <?php
       $host     = "localhost";
       $username = "DB_USER";
       $password = "PASSWORD";
       $db_name  = "DB_NAME";
       $message = "The last person to win the lottery is: ";
       mysql_connect("$host", "$username", "$password") or die (mysql_error ());
       mysql_select_db("$db_name") or die(mysql_error());               
       $total = "SELECT lastWinner AS total FROM info";
       $rs = mysql_query($total);                                                                                              
       while($row = mysql_fetch_array($rs)) {
             echo $message.$row['total'];
       }                                                        
       mysql_close();
    ?>
  </div>

Heres the code that sends the data to the database itself.

  public static boolean updateInfo() {
    try {
        if (Settings.DisableMYSQL == true)
            return false;
        Statement stmt = connection.createStatement();
        if (Lottery.getCurrentLotteryWinner() == null
                && Lottery.getLastLotteryWinner() == null)
            stmt.executeUpdate("UPDATE info SET lastWinner = 'There current isn't a lottery winner!'");
        else if (Lottery.getCurrentLotteryWinner() != null
                && Lottery.getLastLotteryWinner() == null)
            stmt.executeUpdate("UPDATE info SET lastWinner = '"
                    + Lottery.getCurrentLotteryWinner() + "'");
        else
            stmt.executeUpdate("UPDATE info SET lastWinner = '"
                    + Lottery.getLastLotteryWinner() + "'");

            stmt.executeUpdate("UPDATE info SET moneyEarned = '"
                + Lottery.options.size() + "'");
    } catch (Throwable e) {
        if (System.currentTimeMillis() - lastConnection > 10000) {
            destroyConnection();
            createConnection();
            lastConnection = System.currentTimeMillis();
        }
    }
    return false;
}   

我的网络托管服务商遇到了麻烦,做了一些使它起作用的事情。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM