本文介绍了通过URL传递多维数组并在$ _GET中接收并保存到PHP数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我面临着大问题.

我正在为旅行社建立一个网站.

我正在制作一个表单,管理员可以在其中创建新的游览.

一种形式包含与新游览有关的所有信息.
在另一个表格上,管理员将输入该行程的行程.

我有4个字段(白天,城市,行程,夜间住宿城市).

由于游览可能会有所不同.它可能会持续7天或10或15天,因此,我根据巡回演出的天数做了Admin的代码来添加和删除文本框.

现在,我要将整个行程保存在一个表中.

我的问题是如何将整个数组(假设行程为10天,然后是10个行程* 4列)发送到另一种形式,以使用$ _POST通过URL插入表中.另一件事是我应该如何在发布的表单上接收这堆数组并将其保存到表中.

我正在提供我创建的代码,请让我知道如何获取数组中的值并传递到另一页.

这是用于在特定游览名称中插入游览路线的代码.

这是我的javascript代码,单击添加按钮后会创建文本框

Hi
I am facing big problem.

I am making a web site for a travel agent.

I am making a form where the Admin will create a new tour.

One form contain all information related to new tour.
On another Form the Admin will enter the Itinerary for that tour.

I have 4 fields (Day no, City, Itinerary, Night Stay City).

As the tour can be of variable days. It may be for 7 days or 10 or 15 days, so accordingly I did the code for Admin to add and remove the text boxes according to tour''s no of days.

Now I want to save the whole itinerary in a table.

My question is how can i send the whole bunch of array (suppose the tour is or 10 days then 10 itinerary * 4 columns ) to another form for inserting into table using the $_POST thru a URL. And another thing is how should i receive this bunch of array on the posted form and save into table.

I am giving the code which i have created please let me know how can i take the values in array and pass to another page.

This is a code for inserting itineraries for a tour in a particular tourname.

This is my javascript code which create the textboxes after clicking Add Button

<script type="text/javascript">

$(document).ready(function(){

    var counter = 2;

    $("#addButton").click(function () {

    if(counter>30){
            alert("Only 30 textboxes allow");
            return false;
    }

    var newTextBoxDiv = $(document.createElement('div')).attr("id", 'TextBoxDiv' + counter);
    newTextBoxDiv.after().html(
          '<input type="text" name="textbox' + counter +'" id="textbox' + counter + '" value="'+ counter + '" >' +
          '<input type="text" name="textbox' + counter +'" id="textbox' + counter + '" value="" >'+
          '<input type="text" name="textbox' + counter +'" id="textbox' + counter + '" value="" >'+
          '<input type="text" name="textbox' + counter +'" id="textbox' + counter + '" value="" >' );

    newTextBoxDiv.appendTo("#TextBoxesGroup");
    counter++;
     });


     $("#removeButton").click(function () {
    if(counter==1){
          alert("No more textbox to remove");
          return false;
       }

    counter--;

        $("#TextBoxDiv" + counter).remove();

     });

     $("#getButtonValue").click(function () {

    var msg = '';
    for(i=1; i<counter;>    {
      msg += "\n No. of day #" + i + " : " + $('#textbox' + i).val();
    }
          alert(msg);


     });
  });
</script>



现在,我为您提供文本框的html代码.



Now I am giving you the html code for text boxes.

<form id="form1" name="form2" method="post"  onsubmit="" action="addtour_itinerary.php"  >
        <table width="717" height="123">
          <!--DWLayoutTable-->
          <tr>
            <td height="27" colspan="4" align="center" valign="middle" bgcolor="#FFEAFF">Enter Itinerary Details</td>
            </tr>
          <tr>
            <td height="27" colspan="2" valign="top" bgcolor="#FFEAFF">Name of Tour (category)</td>
              <td colspan="2" align="center" valign="middle" bgcolor="#FFFFCC"><label>
              <?php echo $_SESSION['tourname'];??></label></td>
            </tr>
          <tr>
            <td width="61" height="27" valign="top" bgcolor="#E1E1E1">Days</td>
            <td width="140" valign="top" bgcolor="#E1E1E1">City</td>
            <td width="345" valign="top" bgcolor="#E1E1E1">Itinerary</td>
          <td width="145" valign="top" bgcolor="#E1E1E1">Night Stay</td>
          </tr>
          <tr>
            <td height="48" colspan="4" valign="top" bgcolor="#E1E1E1">
                <!--<input type="text" name="days" id="days" />-->

                <div id="TextBoxesGroup">

                  <div id="TextBoxDiv1">

                    <label></label>

                    <input type='text'  id='dayNo'  name="itinerary[]" >
                    <input type="text"  id='cityName'  name="itinerary[]">
                    <input type='text'  id='schedule'  name="itinerary[]">
                    <input type='text'  id='nightStay'  name="itinerary[]">

                  </div>

                </div>

                <input type='button' value='Add Button' id='addButton'>
                <input type='button' value='Remove Button' id='removeButton'>
                <input type='button' value='Get TextBox Value' id='getButtonValue'>
                <input type="submit" name="submit" id="submit" value="Submit" />

                </td>
            </tr>
          </table>
        </form>


现在我想问一下我是否正确创建了文本框数组.我的代码有什么问题.我应该如何收集输入到文本框中的值并传递到php页面,以便可以将其保存在表中.如何将发送数组保存到表中.
我可以在整个会话中传递整个数组以及如何接收这些值,我想知道获取数组值后应该在VALUES()中写些什么.

在此先感谢.


Now i want to ask does i have created the array of textboxes correctly or not. what is wrong with my code. how i should collect the values entered into the textboxes and pass to the php page so that i can be saved in table. How can i save the send array into table.
Can i pass the whole array thru session and how to receive those values, i would like to know what should i write in VALUES( ) after Getting the array values.

Thanks in Advance.

推荐答案

<script type="text/javascript">




这篇关于通过URL传递多维数组并在$ _GET中接收并保存到PHP数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 18:47