php
2013-04-04 40 views 1 likes 
1

我試圖從$ _POST中檢索id,但是如果沒有輸入preg_matchpreg_match文本後的id號

我已經試過:

echo "<b>Image: </b><input type='text' name='image_" . $row['id'] . "' value='"; 


... 
    foreach ($_POST as $key => $value) 
     { 
     if (preg_match('^image_(\d*)$', $key, $matches)) 
      { 
      $id = $matches[1]; 
      if (isset($_POST['title_' . $id])) 
       { 
       mysql_query("UPDATE table SET title='" . $_POST['title_' . $id] . "' where id='$id'"); 
       } 
      } 
     } 

回答

3

你缺少delimiters

'^image_(\d*)$' 

應該是(例如):

'/^image_(\d*)$/' 
+1

如此接近..謝謝:) – rabotalius 2013-04-04 18:17:20

相關問題