Getting a variable from POST and redirect
I managed to solve 90% of my problem from an earlier question, I'll ask it separately because the original one is overly complicated, while now I just need something I believe is really easy.
I have the following code:
// 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
and I can successfully get the "id" I need to create a link, if I manually provide the $value variable, like this:
<a href="<?php echo $baseurl; ?>/index.php?option=com_content&view=article&id=<?php echo $row['id']; ?>">Test test!</a>
It works. Great.
Now, I need to be able to input the $value
from a form. I've been using something similar, but I can't figure out how to set up the method and action of the form.
What I've been using in the past is:
<?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>
Now, how do I modify the code above to take $value from the input and use it to redirect the user to开发者_运维知识库 a link constructed like the one I wrote above?
I know it's probably really easy, but I'm stuck.. Please, help! :)
--- Update ---
Ok, I think I'm getting close. My current code is:
<?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>
but I'm getting redirected to my base url. What am I doing wrong?
Try this:
<?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>
精彩评论