2013-05-16 40 views
0

我想弄清楚如何將從sql數據庫收集的窗體數據傳遞到新窗口。 這個想法是,當用戶點擊'Rediger'(編輯),一個新的小窗口將打開當前數據和一個輸入字段供用戶更改數據,然後點擊保存按鈕以使數據成爲寫入數據庫。然後窗口必須關閉,原始頁面將使用新數據更新。 這可能嗎? 任何人都可以請幫助我嗎? 謝謝。將窗體數據傳遞到新窗口進行編輯並保存

退房這裏的頁面:http://kristoff.it/onlinecoaching/coach/ 這裏是我的代碼:

<?php 
/*Template Name: coach*/ 
?> 
<?php 
session_start(); 
$coachId = $_SESSION['coachId']; 
$fornavn = $_SESSION['fornavn']; 
$efternavn = $_SESSION['efternavn']; 
$titel = $_SESSION['titel']; 
$beskrivKort = $_SESSION['beskrivKort']; 
$tlf = $_SESSION['tlf']; 
$email = $_SESSION['email']; 
$skype = $_SESSION['skype']; 
$messenger = $_SESSION['messenger']; 
$session30 = $_SESSION['session30']; 
$session60 = $_SESSION['session60']; 
?> 
<!doctype html> 
<html <?php language_attributes(); ?>> 
<head> 
<meta charset="<?php bloginfo('charset');?>"> 
<title> 
<?php 

global $page, $paged; 
wp_title('|', true, 'right'); 
bloginfo('name'); 
$site_description = get_bloginfo('description', 'display'); 
if ($site_description && (is_home() || is_front_page())) 
    echo " | $site_description"; 
if ($paged >= 2 || $page >= 2) 
    echo ' | ' . sprintf(__('Page %s'), max($paged, $page)); 
?> 
</title> 
<link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo('stylesheet_url'); ?>" /> 
<link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" /> 

<!--[if lt IE 9]> 
<script src="<?php echo get_template_directory_uri(); ?>/js/html5.js" type="text/javascript"></script> 
<![endif]--> 
<?php if (is_singular() && get_option('thread_comments')) wp_enqueue_script('comment-reply'); ?> 
    <?php wp_head(); ?> 


</head> 

<body <?php body_class(); ?>> 
<div class="outerWrapper"> 
<div><img src="http://kristoff.it/onlinecoaching/wp-content/uploads/2013/05/logo.png" width="726" height="114" alt="OnlineCoaching"></div> 
<div align="center"> 
<div class="contentForside"> 

<form method="POST" action="" id="submitcoach">  
<? 
        $sql = "SELECT * FROM coach where coachId=1"; 

        $result = mysql_query($sql);     
        while($row=mysql_fetch_assoc($result)) 
        { 

         echo '<div class="coachgreen">';  
         echo '<h1>Velkommen coach&nbsp;' . $row['fornavn'] . '</h1>'; 
         echo '<div class="coachwhite">';  

         echo '<table border="0" align="left" width="99%">';       
         echo '<tr><td align="center" valign="top">'; 
         echo '<table border="0" valign="top" width="130">'; 

         echo '<tr><td><img id="coachImg" src="' . $row['imgUrl'] . '" width="110" height="120" alt="' . $row['imgAlt'] . '"></td></tr>'; 
         echo '<tr><td valign="top"><p>Skift billede</p></td></tr>'; 
         echo '<tr><td valign="top">&nbsp;</td></tr>'; 

         echo '<tr><td><img id="coachImg" src="http://kristoff.it/onlinecoaching/wp-content/uploads/2013/05/allanscherfig_video.jpg" width="110" height="120" alt="' . $row['imgAlt'] . '"></td></tr>'; 

         echo '<tr><td valign="top"><p>Upload ny video</p>' . '</td></tr>'; 
         echo '</table>'; 
         echo '</td>';         
         echo '<td valign="top"><br>'; 

         echo '<table width="100%" border="0">'; 

         echo '<tr height="25">'; 
         echo '<td valign="top"width="15%"><p id="coach"><b>Titel</b></p></td>'; 
         echo '<td valign="top"><p id="coach">' . $row['titel'] . '</p></td>'; 
         echo '<td><p id="coach">Rediger</p></td>'; 
         echo '</tr>'; 

         echo '<tr height="25">'; 
         echo '<td valign="top"><p id="coach"><b>Beskrivelse kort</b></p></td>'; 
         echo '<td valign="top"><p id="coach">' . $row['beskrivKort'] . '</p></td>'; 
         echo '<td valign="top"><p id="coach">Rediger</p></td>'; 
         echo '</tr>'; 

         echo '<tr height="110">'; 
         echo '<td valign="top"><p id="coach"><b>Beskrivelse lang</b></p></td>'; 
         echo '<td valign="bottom"><div id="beskrivLang"><p id="coach">' . $row['beskrivLang'] . '</p></div></td>'; 
         echo '<td valign="top"><p id="coach">Rediger</p></td>'; 
         echo '</tr>'; 

         echo '<tr height="10"><td colspan="3">&nbsp;</td></tr>'; 

         echo '<tr height="25">'; 
         echo '<td valign="top"><p id="coach"><b>Brugernavn</b></p></td>'; 
         echo '<td valign="top"><p id="coach">brugernavn</p></td>'; 
         echo '<td valign="top"><p id="coach">&nbsp;</p></td>'; 
         echo '</tr>'; 

         echo '<tr height="25">'; 
         echo '<td valign="top"><p id="coach"><b>Adgangskode</b></p></td>'; 
         echo '<td valign="top"><p id="coach">Adgangskode</p></td>'; 
         echo '<td valign="top"><p id="coach">Skift</p></td>'; 
         echo '</tr>';       

         echo '<tr height="25">'; 
         echo '<td valign="top"><p id="coach"><b>Klient telefon</b></p></td>'; 
         echo '<td valign="top"><p id="coach">' . $row['tlf'] . '</p></td>'; 
         echo '<td valign="top"><p id="coach">Skift</p></td>'; 
         echo '</tr>'; 

         echo '<tr height="25">'; 
         echo '<td valign="top"><p id="coach"><b>Skype</b></p></td>'; 
         echo '<td valign="top"><p id="coach">' . $row['skype'] . '</p></td>'; 
         echo '<td valign="top"><p id="coach">Skift</p></td>'; 
         echo '</tr>'; 

         echo '<tr height="22">'; 
         echo '<td valign="top"><p id="coach"><b>Messenger</b></p></td>'; 
         echo '<td valign="top"><p id="coach">' . $row['messenger'] . '</p></td>'; 
         echo '<td valign="top"><p id="coach">Skift</p></td>'; 
         echo '</tr>';              

         echo '<tr height="42">'; 
         echo '<td align="right" valign="bottom">&nbsp;</td>'; 
         echo '<td valign="top">&nbsp;</td>'; 
         echo '<td valign="top">&nbsp;</td>'; 
         echo '</tr>';      

         echo '</table>'; 

         echo '</td></tr>'; 
         echo '</table'; 

        }           
       ?> 
</form> 
</div> 
</div> 
</div> 

</div><!-- end contentForside --> 
</div><!-- end center --> 
</div> <!-- end outerWrapper --> 

<div align="center"> 
    <div class="copyright"> 
    <?php echo 'copyright © ' . date('Y ') . '<a href="http://www.kristoff.it">kristoff.it</a>' ;?> 
    </div> 
</div> 

</body> 
</html> 

回答

0

當您使用表單數據的新頁面進行編輯,包括隱藏字段唯一標識您正在編輯的內容 - 理想一個唯一的鍵和表引用。當他們點擊提交按鈕時,表單處理器會知道該表中的哪個表和條目要更新。

請務必驗證表單中的數據,因爲用戶當然可能試圖惡意修改隱藏的數據。

編輯:一旦你做了更新,你可以重建頁面並顯示給用戶 - 他們看起來已經更新了原始頁面中的一個字段。

您可以使用AJAX動態做了更新,但是這是一個較長的故事...

+0

我想這樣的事情,但我真的不,現在我在做什麼.. < form method =「POST」action =「」id =「submitcoach」target =「newWindow」> <輸入的ID = 「Button1的」 類型= 「按鈕」 值= 「Rediger」 平變化= 「運行()」> <腳本類型= 「文本/ JavaScript的」> \t \t \t \t \t \t \t fu nction的run(){ \t \t \t \t \t \t \t \t的document.getElementById( 「影片名稱」); \t \t \t \t \t \t \t \t \t \t \t \t \t \t newWindow.document.write(ID); \t \t \t \t \t \t \t \t \t回報newWindow; \t \t \t \t \t \t \t} –

相關問題