gpt4 book ai didi

php - Mysqli 查询在服务器中不工作并且在本地运行正常

转载 作者:行者123 更新时间:2023-11-29 02:14:51 24 4
gpt4 key购买 nike

我不明白这里发生了什么。这是我的代码:

    <?php
function chestnum(){
$servername = "localhost";
$username = "athletics";
$password = "";
$dbname = "athletics";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
//selecting all chest number unallotted students
$query = 'SELECT * FROM student WHERE CHEST = 0';
$result = mysqli_query($conn, $query);
//selecting all departments' max chest number
//$query = 'SELECT MAX(CHEST) FROM student GROUP BY batch';
//$max = mysqli_query($conn, $query);
while($row = mysqli_fetch_assoc($result)){
$batch = $row['batch'];
$roll = $row['roll'];
$q = "SELECT MAX(`CHEST`) FROM `STUDENT` WHERE `batch`='$batch'";
//$q = "SELECT MAX(CHEST) WHERE batch = $batch";
$allmax = mysqli_query($conn, $q);
while($rowm = mysqli_fetch_assoc($allmax))
{
echo $max=$rowm['MAX(`CHEST`)'];
}
//echo $cse = $bcr;echo $csa = $bcr;echo $me = $bcr; echo $ece = $bcr;echo $eee = $bcr;
/*
CHEST NUMBER ALLOCATION INFO
//100-250mech, 251-400ec, 401-550eee, 551-700cse, 701-850csa
*/
//Checking for the department and setting chest number
if($batch==1 && $max==0){
$q = "UPDATE student SET CHEST = 100 WHERE roll LIKE '$roll'";
} else if($batch==1 && $max == 250) {
$q = "UPDATE student SET CHEST = 900 WHERE roll LIKE '$roll'";
} else if($batch==1){
$max++;
$q = "UPDATE student SET CHEST = $max WHERE roll LIKE '$roll'";
}
if($batch==2 && $max==0){
$q = "UPDATE student SET CHEST = 251 WHERE roll LIKE '$roll'";
} else if($batch==2 && $max == 400) {
$q = "UPDATE student SET CHEST = 1000 WHERE roll LIKE '$roll'";
} else if($batch==2) {
$max++;
$q = "UPDATE student SET CHEST = $max WHERE roll LIKE '$roll'";
}
if($batch==3 && $max==0){
$q = "UPDATE student SET CHEST = 401 WHERE roll LIKE '$roll'";
} else if($batch==3 && $max == 550) {
$q = "UPDATE student SET CHEST = 1100 WHERE roll LIKE '$roll'";
} else if($batch==3) {
$max++;
$q = "UPDATE student SET CHEST = $max WHERE roll LIKE '$roll'";
}
if($batch==4 && $max==0){
$q = "UPDATE student SET CHEST = 551 WHERE roll LIKE '$roll'";
} else if($batch==4 && $max == 700) {
$q = "UPDATE student SET CHEST = 1200 WHERE roll LIKE '$roll'";
} else if($batch==4) {
$max++;
$q = "UPDATE student SET CHEST = $max WHERE roll LIKE '$roll'";
}
if($batch==5 && $max==0){
$q = "UPDATE student SET CHEST = 701 WHERE roll LIKE '$roll'";
} else if($batch==5 && $max == 850) {
$q = "UPDATE student SET CHEST = 1300 WHERE roll LIKE '$roll'";
} else if($batch==5) {
$max++;
$q = "UPDATE student SET CHEST = $max WHERE roll LIKE '$roll'";
}
//assigning the chest number
mysqli_query($conn, $q);
}
}
?>

代码在我的本地机器上测试时运行良好,但在服务器上执行时却什么也没有显示。执行时没有报错。从另一个文件调用函数 chestnum。

最佳答案

这可能是显而易见的,但如果您还没有这样做,请更改您的服务器名称。如果它在本地主机上工作,那是因为您的服务器名称是本地主机。在你的网站上,转到你的控制面板并找到 mysql 区域,它会给你你应该使用的服务器名称,尽管它可能被称为主机名。将其复制到您拥有本地主机的位置。数据库名称也可能不同,但它会列在您的网络服务器控制面板上。

关于php - Mysqli 查询在服务器中不工作并且在本地运行正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41769267/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com