2013-07-09 481 views
-3

我需要一些帮助:更新日期和时间在MySQL

  1. 我有被安排在表
  2. 的形式在每行数据的列表,有文字,在对话框中的日期和时间进入
  3. 我需要更新的日期和时间到数据库

我没能获得在$_REQUEST因为ID文本框的我有文本框的值给定就像date$counter,因为每一行都必须是唯一的。

代码示例:

<table><tr><td> 
      <input type='text' name='date$counter_sno' id='sel$counter_sno' size='15' value=''> 
      <input type='reset' value='...' id='button$counter_sno'> 

     <script type='text/javascript'> 
     var cal = new Zapatec.Calendar.setup({ 
     inputField  : 'sel$counter_sno',  // id of the input field 
     singleClick :  false,  // require two clicks to submit 
     ifFormat  : '%Y-%m-%d %H:%M',  // format of the input field 
     showsTime  :  true,  // show time as well as date 
     button   : 'button$counter_sno' // trigger button 
     }); 

    </script> 
</td> 
</tr> 
</table> 

回答

1

问题我不能得到文本框的值$ _REQUEST因为文本框我给的ID就像是日期$计数器,因为每一行必须是唯一的。

我不知道你为什么要使用$_REQUEST。你真的应该使用$_POST来代替。其次,从文本框ID中取出$字符。它确实不需要在那里。这是一个可与$_POST模型配合使用的HTML模型。

<form method="post" action="page.php"> 
    <input type="text" id="tb1" name="tb1"/> 
    <input type="submit" id="submit" name="submit"/> 
</form> 

请记住,我已经给它一个id-name对。这是因为PHP将使用name属性。我已经给它一个id,因为你的代码似乎有一些Javascript,并且得到一个元素的id属性。在你page.php的代码,你可能有这样的事情:

<?php 
    if($_POST) { 
     $textboxValue = $_POST['tb1']; 
     // We now have the value in the textbox. 

     $dbh = new PDO(// Add your database details); 

     $statement = $dbh->prepare("INSERT INTO Table VALUES(:textboxValue)"); 

     $statement->bindParam(':textboxValue', $textboxValue); 
     // Create a prepared statement with the value from the textbox and execute. 
     $statement->execute(); 
    } 
?> 
+0

感谢您的帮助 –

+0

+1。另外,用'if($ _POST){'包装表单处理程序,这样get操作不会尝试写入数据库。 – halfer

+0

好点@halfer。修正。 – christopher