PHP / MYSQL - 传递变量问题

时间:2012-12-16 17:50:29

标签: php jquery mysql variables

我正在开发一个JQuery脚本,它基本上根据输入从选择框中提取数据,并根据选择隐藏/显示变量(当前测试数据)

我让脚本工作到JQUERY刷新和更新值。我目前的问题是,我似乎无法通过其他步骤来传递变量。

这是我到目前为止所拥有的。现在我在将变量传递到下一步时遇到了问题。

这是JQuery / HTML部分:

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script type="text/javascript"><!--
$(document).ready(function() {
  // When the form is submitted to PHP Call
  $('#crs').submit(function() {
    // Get form data ready for PHP Call
    var Sphone = $('#crs #Sphone').val();
    var Schat = $('#crs #Schat').val();
    var Smeet = $('#crs #Smeet').val();
    var Sremo = $('#crs #Sremo').val();
    var Sport = $('#crs #Sport').val();
    var Smail = $('#crs #Smail').val();
    var Svoic = $('#crs #Svoic').val();
    var Sfax = $('#crs #Sfax').val();


    // put form data in a JSON format that will be sent to the PHP File
    var data_json = {'Sphone':Sphone, 'Schat':Schat, 'Smeet':Smeet, 'Sremo':Sremo, 'Sport':Sport, 'Smail':Smail, 'Svoic':Svoic, 'Sfax':Sfax};

    // Set AJAX method
    // If succeeds, goes to the  next step
    $.ajax({
      type: 'post',
      url: 'script.php',
      data: data_json,
      beforeSend: function() {
        // before send the request, displays a "Loading..." messaj in the element where the server response will be placed
        $('#resp').html('Loading...');
      },
      timeout: 10000,        // sets timeout for the request (10 seconds)
      error: function(xhr, status, error) { alert('Error: '+ xhr.status+ ' - '+ error); },
      success: function(response) { $('#resp').html(response); }
    });

    return false;      // required to not open the page when form is submited
  });
});
--></script>
</head>
<body>
<div id="resp"></div>
<h4>Fill the form:</h4>
<form action="script.php" method="post" id="crs">
Phone Support: <select name="Sphone" id="Sphone">
  <option value="Pen1">Yes</option>
  <option value="">No</option>
   </select><br />

Live Chat Support: <select name="Schat" id="Schat">
  <option value="Pen2">Yes</option>
  <option value="">No</option>
   </select><br />

Live Meeting: <select name="Smeet" id="Smeet">
  <option value="Pen3">Yes</option>
  <option value="">No</option>
   </select><br />
Remote Support: <select name="Sremo" id="Sremo">
  <option value="Pen3">Yes</option>
  <option value="">No</option>
   </select><br />
Ticket By Portal: <select name="Sport" id="Sport">
  <option value="Pen3">Yes</option>
  <option value="">No</option>
   </select><br />

Ticket By Email: <select name="Smail" id="Smail">
  <option value="Pen3">Yes</option>
  <option value="">No</option>
   </select><br />

Ticket By Voicemail: <select name="Svoic" id="Svoic">
  <option value="Pen3">Yes</option>
  <option value="">No</option>
   </select><br />

Ticket By Fax: <select name="Sfax" id="Sfax">
  <option value="Pen3">Yes</option>
  <option value="">No</option>
   </select><br />

 <input type="submit" value="submit" />
</form>

这是PHP部分。

if(isset($_POST['Sphone']) && isset($_POST['Schat']) && isset($_POST['Smeet']) && isset($_POST['Sremo']) && isset($_POST['Sport']) && isset($_POST['Smail']) && isset($_POST['Svoic']) && isset($_POST['Sfax'])) {
  $_POST = array_map("strip_tags", $_POST);       // Gets rid of tags in POST Call

  // get data
  $Sphone = $_POST['Sphone'];
  $Schat = $_POST['Schat'];
  $Smeet = $_POST['Smeet'];
  $Sremo = $_POST['Sremo'];
  $Sport = $_POST['Sport'];
  $Smail = $_POST['Smail'];
  $Svoic = $_POST['Svoic'];
  $Sfax = $_POST['Sfax'];

// Define Full Output of variable   
  $arrow ='<textarea name="supportArticle" cols="160" rows="15" wrap="virtual">'.$Sphone.' <br> '.$Schat.' <br> '.$Smeet.' <br> '.$Sremo.' <br> '.$Sport.' <br> '.$Smail.' <br> '.$Svoic.' <br> '.$Sfax.'</textarea>';
   function passVariable($arrow)
    {
    return $arrow or die(mysql_error());
    }
  }
echo $arrow; 

我确实有更多代码,但这只是数据库连接等。

这可以很好地改变变量。现在我有笔1,笔2等...作为占位符(中间有间隔)。

我想将所有这些保存到一个文件中。我用一个名为$ arrow的变量对它进行了测试,它不会回显这个变量(也给它添加了一个DIE错误,然后删除了) - 任何接受者?

0 个答案:

没有答案