Jump to content

passing variable to url


jonwish

Recommended Posts

Hi, My first post so please excuse if im ake any mistakes.

 

I have a drop down that I am getting a post variable from with i am then trying to append an URL with.

It works but only for the first option.

Any help much appreciated.

When I echo the $pagelink it shows the correct value but when I add it to the header location it just goes to the homepage of the site (except the first option)!

 

My index.php:

<?php
// connect to db
mysql_connect ("xxxxxx", "xxxxx","")  or die (mysql_error());
mysql_select_db ("xxxxxx");

//query
$sql = mysql_query('SELECT product_id, name FROM  CubeCart_inventory');
$models = array();
while ($row = mysql_fetch_array($sql)){
    $models[] = $row;
}
?>

<form action="config.php" method="POST">
  <select name="battery">
  <?php
  foreach ($models as $model) {
  ?>
    <option value="<?php echo $model['name']?>"><?php echo $model['name']?></option>
  <?php
  }
  ?>
  </select>
  <input type="submit" name="submit" value="Submit" />
</form>

my config.php:

<?php

//var_dump($_REQUEST); 
 	$name = $_POST['battery'];
	$pagelink = str_replace(" ","-",$name);
	$pagelink = strtolower($pagelink);
	$pagelink = $pagelink.".html";
	
header ('Location: http://localhost/carrotcycles/test-category/'$pagelink);
?>

Link to comment
Share on other sites

Thanks for the reply. I have added the alterations as you mentioned to secure the data but I think maybe I have not explained myself properly (my fault).

 

The dropdown populates okay and if I echo $pagelink it shows the correct link but when I add $pagelink to the header location it only allows the first item from the db to link okay, the rest just go to the homepage with http://www.xxxxxxxx/index.php

 

I am completely stuck with this as it is echoing the results exactly as it should.

Link to comment
Share on other sites

Maybe the issue isn't the header on the config but rather a header on the page you are linking to. Where does the $pagelink go to and what does that page do with the URL var? If there is a header on that page to go back to the index if something is wrong, maybe that's where the problem is.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.