dongsuoying9059 2015-06-16 00:06
浏览 40

将MySQL数据发布到PHP列中[重复]

This question already has an answer here:

im working on a project for basically my friends and i to use. Maybe to use it for other games as well. SpeedRunning! i have made and was able to POST the Data into MySQL with THIS information

<?php include_once('include/action_page.php');?>
<!DOCTYPE HTML>
<meta charset="UTF-8">
<html>
<head>
<title>Roleplayer's Tavern Home</title>
<link href="/style/style.css" rel="stylesheet" type="text/css">
<script src="/include/jquery-1.11.2.min.js"></script>
<?php include_once('/include/rpt_site_no_script.php');?>

</head>
<body onload="">
<div class="page_container" name="page_container">
    <div id="page_header">
        <!-- The title of the webpage -->
        <div style="max-width:250px; overflow:hidden">
          <span id="header_title"><img src="style/logo.png"     style="width:225px; height:67px;"/></span>
          </div>

    </div>
    <!-- Left side bar -->
    <div id="page_container_left">
        <h3 id="page_content_header">Submit your data!</h3>

<?php include('include/submit_data.php');?>

    </div>
    <div id="page_container_right"
        style="overflow-y: auto; max-height: 100%">
        <h3 id="page_content_header">Donations for website?</h3>
        <?php 

        ?>
    </div>
    <!-- Main Content -->
    <div id="page_content_container_main_page">
        <div class="page_content_container">
            <h2 id="page_content_container_header">Leaderboard WOO WOO</h2>
            <hr>


            <p id="page_content_container_content">


<h2>Players That Have Beaten Mad Pack 2</h2>

    <?php include('include/leaderboard.php');?>
        </div>
    </div>
    <br>
    <!-- Footer -->
<div id="page_footer">
<ol id="footer_list">
    <li>Copyright &copy; Roleplayer's Tavern 2015-2016 - All Rights     Reserved</li>
    <li style="font-size:12px">Your IP address <?php echo         $_SERVER['REMOTE_ADDR']; ?> will be logged for security reasons.</li>
</ol>
</div>


</div>
<script type="text/javascript">
var element=document.getElementsByName('page_container')[0];
var applyTo=document.getElementById('page_container_left');
var applyTo2=document.getElementById('page_container_right');
applyTo.style.height = (element.offsetHeight - 2) + "px";
applyTo2.style.height = (element.offsetHeight - 2) + "px";

window.onresize = function(event) {
    var element=document.getElementsByName('page_container')[0];
    var applyTo=document.getElementById('page_container_left');
    var applyTo2=document.getElementById('page_container_right');
    applyTo.style.height = (element.offsetHeight - 2) + "px";
    applyTo2.style.height = (element.offsetHeight - 2) + "px";
}
</script>

</body>
</html>

as this is the HTML format.

Action_page.php is the page for submitting the information

<?php 
$servername = "localhost";
$username = "USERNAME";
$password = "PASSWORD";
$mysqlDatabaseName = "SpeedRun";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $mysqlDatabaseName);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);

$sql = "INSERT INTO MineCraftRecords (MineCraftName, LevelSeed, Day, Time)
VALUES ('$_POST[MinecraftName]', '$_POST[LevelSeed]', '$_POST[Day]',     '$_POST[Time]')";

if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} 
echo "Turtle Mode Activated";
$conn->close();
?>
<meta http-equiv="Location" content="https://rptavern.org/SpeedRun/">

and im having trouble on getting the page to LOAD the information provided into the leaderboard.php as this is what i have so far.

<?php
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);

$servername = "localhost";
$username = "USERNAME";
$password = "PASSWORD";
$mysqlDatabaseName = "SpeedRun";

$query="SELECT * FROM MineCraftRecords";$result=mysql_query($query);
$num=mysql_numrows($result);
$i=0;while ($i < $num) {CODE$i++;}
$variable=mysql_result($result,$i,"fieldname");
$field1-name=mysql_result($result,$i,"MineCraftName");
$field2-name=mysql_result($result,$i,"LevelSeed");
$field3-name=mysql_result($result,$i,"Day");
$field4-name=mysql_result($result,$i,"Time");
$field5-name=mysql_result($result,$i,"id");


// Create connection
$conn = mysqli_connect($servername, $username, $password,     $mysqlDatabaseName);  
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}   
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}  
echo "Turtle Mode Activated";
?>

Im basically trying to base it off this website http://www.speedrun.com/mc but not as technical. Just to show the SpeedRunning time and have the TIME the top of the list.

Any help is awesome, as im very new to creating stuff like this. i will take the time to read everyone's comments and suggestions that you all can provide :D

</div>
  • 写回答

2条回答 默认 最新

  • duanbiaoshu2021 2015-06-16 00:44
    关注

    I suggest cleaning up your code. Some thing that can be done is that you can separate the dB connect details into a separate file. This will optimize your code and will it make sure to change the details later on as your project grows.

    评论

报告相同问题?

悬赏问题

  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 关于无人驾驶的航向角
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了