从POST获取变量并重定向

时间:2011-10-14 20:30:31

标签: php post joomla1.5

我设法从之前的问题中解决了90%的问题,我会单独问它,因为原来的问题过于复杂,而现在我只需要一些我认为非常容易的东西。

我有以下代码:

// Make a MySQL Connection
$Db =& JFactory::getDBO();
$baseurl = JURI::base();
// Get a specific result from the "example" table
$result = mysql_query("SELECT * FROM jos_content WHERE pass='$value'") or die(mysql_error());  

// get the first (and hopefully only) entry from the result
$row = mysql_fetch_array( $result );
// Print out the contents of each row into a table 

如果我手动提供$ value变量,我可以成功获得创建链接所需的“id”,如下所示:

<a href="<?php echo $baseurl; ?>/index.php?option=com_content&view=article&id=<?php echo $row['id']; ?>">Test test!</a>

有效。大。

现在,我需要能够从表单输入$value。我一直在使用类似的东西,但我无法弄清楚如何设置表单的方法和操作。

我过去一直在使用的是:

<?php 
if(isset($_POST['number'])){
    header('Location: http://www.yourdomain.tld/'.$_POST['number']);
    exit;
}
?>

<form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <input type="text" name="folder" id="folder" />
    <input type="submit" name="number" id="bt" value="Go To" />
</form>

现在,如何修改上面的代码以从输入中获取$ value并使用它将用户重定向到像我上面编写的那样构建的链接?

我知道这可能很容易,但我被困了..请帮助! :)

---更新---

好的,我想我已经接近了。我目前的代码是:

<?php
// Make a MySQL Connection
$Db =& JFactory::getDBO();
$baseurl = JURI::base();
$value = $_POST;
// Get a specific result from the "example" table
$result = mysql_query("SELECT * FROM jos_content WHERE pass='$value'") or die(mysql_error());  
// get the first (and hopefully only) entry from the result
$row = mysql_fetch_array( $result );
// Print out the contents of each row into a table 

if(isset($_POST['password'])){
    header('Location: http://myurl.com/index.php?option=com_content&view=article&id='.$row['id']);
    exit;
}

?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    Password:  <input type="text" name="password" /><br />
    <input type="submit" name="submit" value="Submit me!" />
</form>

但我正被重定向到我的基本网址。我做错了什么?

1 个答案:

答案 0 :(得分:0)

试试这个:

<?php 
if(isset($_POST['number'])){
    header('Location: http://www.yourdomain.tld/index.php?option=com_content&view=article&id=' . $_POST['folder']);
    exit;
}
?>

<form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <input type="text" name="folder" id="folder" />
    <input type="submit" name="number" id="bt" value="Go To" />
</form>
相关问题