Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

post value not working in header location?

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

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
<?php
// connect to db
mysql_connect ("xxxxxxxx", "xxxxxxxxx","xxxxxxx")  or die (mysql_error());
mysql_select_db ("xxxxxxx");

//query
$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']!="") { 
   $statement="";
   $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>
  <?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>
<?php }  ?>
jonwish
New php-forum User
New php-forum User
 
Posts: 2
Joined: Thu Jun 13, 2013 8:32 am

Return to PHP coding => General

Who is online

Users browsing this forum: Google [Bot], Google Feedfetcher and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron