.jpg正在从数据库中更改为_jpg以获取图像名称

时间:2015-11-16 03:59:50

标签: php html mysqli

我这里有一个脚本,不知何故将.jpg更改为_jpg。

// define module constructor that accepts the io variable
var io;
module.exports = function(importIO) {
    io = importIO;
}

// elsewhere in the module
io.emit(...)
回声"滑块名称:" 。 $ slider->名称;打印出来:

<?php
global $Sys;

//echo $Sys->Auth->chkAuth();
if(isset($_POST['update_slider']))
{
    unset($_POST['update_slider']);
    $post = $_POST;
    unset($_POST);
    foreach($post as $name => $value)
    {   
        $value = (is_numeric($value)) ? $value : intval($value);
        $result = $Sys->db->query("UPDATE dj_photo SET slider_status = $value WHERE name = $name");
    }
    if($result->affected_rows != 0)
    {
        $Sys->Template->setAlerts($result->affected_rows . ' images were added to the image slider.');
    }
    else
    {
        $Sys->Template->setAlerts('No images were added to the slider.', 'error');
    }
}

?>
<div id="webCfg">
<h2>Website Configuration</h2>
  <?php
      global $Sys;

      $alerts = $Sys->Template->getAlerts();
      if ($alerts != '') { echo '<div><ul class="alerts">' . $alerts . '</ul></div>'; }
      $result = $Sys->db->query('SELECT * FROM dj_photo ORDER BY group_name ASC');
    ?>
  <form action="" method="post">
  <table cellpadding="1" cellspacing="0" id="webCfgTbl">
  <tr><td class="label"><label for="submit"></label></td><td class="content"><div class="row submitrow"><input type="submit" id="submit" name="update_slider" class="submit" value="Update Slider" /></div></td></tr>
  <tr>
    <?php
    $i = 1;
      while($slider = $result->fetch_object())
      {
          if($slider->slider_status == 1)
          {
              $add = 'selected';
          }
          else
          {
              $remove = 'selected';
          }
          if(($i % 6) == 0)
          {
            echo "   Slider Name: " . $slider->name;
              echo '<td><div class="adm_slider_pics"><img style="width:180px;height:120px;" alt="' . ucfirst($slider->name) . '" src="../photogallery/' . $slider->img_group . '/' . $slider->name . '" title="' . ucfirst($slider->title) . '" /></a></td><td class="content"><select name="' . $slider->name . '"><option value="1" ' . $add . '>Add</option><option value="0" ' . $remove . '>Remove</option></select></div></td></tr><tr>';
          }
          else
          {
            echo "   Slider Name: " . $slider->name;
              echo '<td><div class="adm_slider_pics"><img style="width:180px;height:120px;" alt="' . ucfirst($slider->name) . '" src="../photogallery/' . $slider->img_group . '/' . $slider->name . '" title="' . ucfirst($slider->title) . '" /></a></td><td class="content"><select name="' . $slider->name . '"><option value="1" ' . $add . '>Add</option><option value="0" ' . $remove . '>Remove</option></select></div></td>';
          }
        $i++;
      }
    ?>
    <tr><td class="label"><label for="submit"></label></td><td class="content"><div class="row submitrow"><input type="submit" id="submit" name="update_slider" class="submit" value="Update Slider" /></div></td></tr>
  </tr></table>
  </form>     
</div>

我添加了print_r($ _ POST);在if之前和之后退出;得到这个:

Slider Name: DSCF3727.jpg Slider Name: DSCF3687.jpg Slider Name: DSCF3744.jpg Slider Name: DSCF4070.jpg Slider Name: DSCF4071.jpg Slider Name: DSCF4073.jpg Slider Name: 10245379_229236400605097_7329379469957650735_n.jpg Slider Name: 10314007_229236253938445_8056225029697636541_n.jpg Slider Name: DSCF3618.jpg Slider Name: 10550825_261238134071590_1715454340087601479_n.jpg Slider Name: 1551739_261238150738255_2482363522486143465_n.jpg Slider Name: 10626882_284760908385979_3153917771920003400_n.jpg Slider Name: 10689730_284760921719311_8515870397004989019_n.jpg Slider Name: DSCF3384.jpg Slider Name: DSCF3382.jpg Slider Name: biker.jpg Slider Name: 10410927_255245578004179_6557207701489592736_n.jpg Slider Name: 10400847_255245548004182_5319163275713658480_n.jpg Slider Name: 111111.jpg Slider Name: DSCF3013.jpg Slider Name: DSCF4040.jpg Slider Name: 1011255_238047056390698_6002378516798338793_n.jpg Slider Name: 10373785_238048733057197_8255990183542589096_n.jpg Slider Name: 10383572_238047003057370_1041466926744898970_n.jpg Slider Name: DSCF4047.jpg Slider Name: DSCF4051.jpg Slider Name: DSCF4109.jpg Slider Name: DSCF4121.jpg Slider Name: DSCF4136.jpg Slider Name: DSCF4029.jpg Slider Name: Rancho-las-lomas-wedding-DJ.jpg Slider Name: webtest.jpg

<?php
global $Sys;

//echo $Sys->Auth->chkAuth();
if(isset($_POST['update_slider']))
{
  print_r($_POST);
  exit;
    unset($_POST['update_slider']);
    $post = $_POST;
    unset($_POST);
    foreach($post as $name => $value)

我很难过。任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:-1)

对于任何想知道如何解决这个PHP问题的人(Not Mysqli问题):

旧:

if(isset($_POST['update_slider']))
{
    unset($_POST['update_slider']);
    $post = $_POST;
    unset($_POST);
    foreach($post as $name => $value)
    {   
        $value = (is_numeric($value)) ? $value : intval($value);
        $result = $Sys->db->query("UPDATE dj_photo SET slider_status = $value WHERE name = $name");
    }
    if($result->affected_rows != 0)
    {
        $Sys->Template->setAlerts($result->affected_rows . ' images were added to the image slider.');
    }
    else
    {
        $Sys->Template->setAlerts('No images were added to the slider.', 'error');
    }
}

新:

if(isset($_POST['update_slider']))
{
    unset($_POST['update_slider']);
    $post = $_POST;
    unset($_POST);
    $search = array('_jpg', '_jpeg', '_png', '_bmp', '_gif');
    $replace = array('.jpg', '.jpeg', '.png', '.bmp', '.gif');
    foreach($post as $name => $value)
    {   
        $column = str_replace($search, $replace, $name);
        $value = (is_numeric($value)) ? $value : intval($value);
        $result = $Sys->db->query("UPDATE dj_photo SET slider_status = '" . $value . "' WHERE name = '" . $column . "'");
    }
    if($result)
    {
        $Sys->Template->setAlerts($result->mysqli_affected_rows . ' images were added to the image slider.');
    }
    else
    {
        $Sys->Template->setAlerts('No images were added to the slider.', 'error');
    }
}