【问题标题】:Pass data from mysql to php to gotowebinar (through form post)将数据从 mysql 传递到 php 到 gotowebinar(通过表单发布)
【发布时间】:2014-06-16 07:00:55
【问题描述】:

我正在尝试从我们的数据库中获取用户数据,然后自动将这些用户传递给我的 gotowebinar。自动化代码将在 php.ini 中完成。这是代码。我想知道为什么它不会将数据传递到 gotowebinar 页面。我能够成功检索数据。但是,当我将表单“post”的代码添加到 gotowebinar 时,它不会传递数据。我希望你能帮我解决这个问题。非常感谢。

<?php

$conn = new mysqli("mywebsite.com", "myusername", "mypassword", "mydatabase");
// check connection
if ($conn->connect_error) {
trigger_error('Database connection failed: '  . $conn->connect_error, E_USER_ERROR);
}

$sql = "SELECT name, email FROM users WHERE username = 'Manny'";

$rs=$conn->query($sql);

$rs->data_seek(0);
while($row = $rs->fetch_assoc()){
?>

<form action="https://attendee.gotowebinar.com/register/11111111111" id="formGTW"   method="post">

<input type="hidden" name="registrant.givenName" value="<?php echo $row['name'] ?>" />
<input type="hidden" name="registrant.surname" value="GTN" />
<input type="hidden" name="registrant.email" value="<?php echo $row['email'] ?>" />

<script type="text/javascript">
$(document).ready(function(){
 $("#formGTW").submit();
});
</script>

<?php } ?>

</form>

【问题讨论】:

  • 您正在多次打印&lt;form ac... 以及 javascript。

标签: php mysql forms post


【解决方案1】:

您正在打印 &lt;form&gt; 以及 while 循环内的 javascript,因此它将被打印多次。

$rs->data_seek(0);?>

<form action="https://attendee.gotowebinar.com/register/11111111111" id="formGTW"   method="post">
<?php while($row = $rs->fetch_assoc()){
?>

<input type="hidden" name="registrant.givenName[]" value="<?php echo $row['name'] ?>" />
<input type="hidden" name="registrant.email[]" value="<?php echo $row['email'] ?>" />
<?php } ?>
<input type="hidden" name="registrant.surname" value="GTN" />
<script type="text/javascript">
$(document).ready(function(){
 $("#formGTW").submit();
});
</script>

注意:我在名称字段中的registrant.givenName 之后添加了[],以便发送所有数据(如果循环运行不止一次)。

【讨论】:

  • 嗨,Subhanker,终于成功了!但是,现在导致错误的是我用于提交表单的 javascript。在我将其替换为“document.getElementById("formGTW").submit();”之后,它现在可以工作了。感谢您对循环安排的帮助。 :)
  • 很高兴看到它有所帮助。
猜你喜欢
  • 1970-01-01
  • 2019-06-26
  • 2017-01-31
  • 1970-01-01
  • 2012-12-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多