post value not working in header location?

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 2
Joined: Thu Jun 13, 2013 8:32 am

post value not working in header location?

Postby jonwish » Sat Jul 13, 2013 9:54 pm

Hi, I have a piece of code that populates a dropdown from my db. alter the code accordingly (removes spaces, etc) then appends a header location for a link to a post dependant page.
The problem is that it only works for one of the post values (first in db) but if I echo the value instead of passing it through header it show the correct link.

Any help most appreciated

Code: Select all

// connect to db
mysql_connect ("xxxxxxxx", "xxxxxxxxx","xxxxxxx")  or die (mysql_error());
mysql_select_db ("xxxxxxx");

$sql = mysql_query('SELECT product_id, name FROM  xxxxxxx_inventory WHERE cat_id = 217');
$models = array();
while ($row = mysql_fetch_array($sql)){
    $models[] = $row;

// process form
if($_POST['submit'] && $_POST['battery']!="") { 
   $name = mysql_real_escape_string($_POST['battery']);
   $pagelink = str_replace(" ","-",$name);
   $pagelink = strtolower($pagelink);
   $pagelink = "www.xxxxxxxxxxxxxxxxx/xxxxxxxxxxxxxxxxx/".$pagelink.".html";
   header ('Location: http://'.$pagelink);
} else {
   $statement = "Please make a selection";
   echo $statement;
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
  <select name="battery">
  <option value="" selected="selected">Select...</option>
  foreach ($models as $model) {
    <option value="<?php echo $model['name']?>"><?php echo $model['name']?></option>
   <input type="submit" name="submit" value="Submit" />
<?php }  ?>

Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 9 guests