php - 我无法从 PHP 中的数据库获取存储值(存储值是没有扩展名的文件名)

标签 php mysql

我正在尝试从数据库中获取文件名$oldfile并将其替换为新文件名$newfile问题是$oldfile返回一个空值,但在数据库中它有一个值。

$oldfile = '';
if(isset($_POST['submit'])){

    $styles=$_POST['styles'];
    $id=intval($_GET['id']);
    $sql=mysqli_query($con,"update styles set stylename='$styles' where id='$id'");

    $file = $oldfile.'.php';

    $tempfile = strtolower($styles);
    $newfile = $tempfile.'.php';

    if(!rename($file, $newfile)){
        $_SESSION['delmsg']="File Not Replaced!";
    }

    $_SESSION['msg']="Styles Updated!".$file;

}

$id=intval($_GET['id']);
$query=mysqli_query($con,"select * from styles where id='$id'");

while($row=mysqli_fetch_array($query)){
    $disp = $row['stylename'];
    $oldfile = strtolower($row['stylename']);
}

最佳答案

看起来您可能会在第一行返回一个空变量。如果注释掉该行,输出是什么:

//$oldfile = ' ';

另外,仅供引用...,您正在设置 $sql 变量,但它没有在其他地方使用:

$sql=mysqli_query($con,"update styles set stylename='$styles' where id='$id'");

关于php - 我无法从 PHP 中的数据库获取存储值(存储值是没有扩展名的文件名),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52895561/

相关文章:

php - 如何在 PHP MYSQL 中缓存 RAND() 随机图像

mysql - 显示表命令的约束

php - 带子查询的慢 MySQL 查询

python - 我如何在 sqlalchemy 中表达这个查询?

用于 SVG 动态图的 PHP 库

php - 如何在 UwAmp CLI 中启用 'openssl'?

php - 如果id在数组中,vuejs检查复选框

mysql - sql选择现在之前的最大日期

javascript - 对表中的列值求和

php - 如何使用python绕过WP super 缓存?