tunage Posted February 26, 2014 Share Posted February 26, 2014 I am trying to do a select / save selection to $_SESSION['id'] / redirect but the only value I am able to pass to $_SESSION['id'] is the target url and not the selection. output -> http://i.imgur.com/QeGb89X.png ************************************ index.php ******************************************<?php require_once("header.php");?><!-- <form name="addjob" method="POST" action="" onsubmit="return getURL(add-job.php)> --><form name="addjob" method="POST" action="" onsubmit="return getURL(add-job.php)"><select name="bolredir"><?php// selection box submit$query = "SELECT * FROM customer";$result = $odb->query($query);$custkey;// var_dump($result);if($result->rowCount() > 0) {foreach($result as $item) {echo '<option value='.$item['id'].'>';echo ($item['cust_name'] .",". $item['cust_addr'] .",". $item['cust_phone'] .",". $item['id']."<br />\n");echo '</option>';$_SESSION['id'] = $item['id'];}}// var_dump($_SESSION['cust_name']);?></select><input type="submit" id="id" name="id" value="add-job.php"></form></body>***************************************** header.php ***********************************darknet064tokyo contactdb # cat header.php<?phpsession_start();if(isset($_POST['id'])){//store as session variable$_SESSION['id'] = $_POST['id'];//forward browserheader("Location: ".$_SESSION['id']);exit;}$host = "localhost";$user = "custdb";$pass = "";$db = "accounting";$odb = new PDO("mysql:host=" . $host . ";dbname=" . $db, $user, $pass);?> Quote Link to comment Share on other sites More sharing options...
tunage Posted February 27, 2014 Author Share Posted February 27, 2014 the id field has the value I need in $_SESSION['id'] which is gained via the -> $query = "SELECT * FROM customer"; (it is an auto increment distinct value). I need this value carried over to add-job.php from index.php via the $_SESSION['id'] variable. This is a dynamic value returned from the database query.mysql> SELECT * FROM customer -> ;+----+-----------+------------+------------+------------+| id | cust_name | cust_addr | cust_phone | cust_email |+----+-----------+------------+------------+------------+| 1 | bob | 666 bo rd | 2124442222 | bo@bo.com || 2 | dude | 666 jo rd | 2124445555 | bub || 3 | nnn | kju | 6666 | bo@bo2.com || 4 | brad | 888 | 2124444444 | bo@jack.am || 5 | brad2 | smirk | 2147483647 | go@jac.com || 6 | another | 8888 bh rd | 2147483647 | knarly@me || 7 | peach | 69 too | 2147483647 | iuhdihih || 8 | peachy | 4442222 rd | 0 | do@do.com |+----+-----------+------------+------------+------------+8 rows in set (0.00 sec)mysql> desc customer;+------------+--------------+------+-----+---------+----------------+| Field | Type | Null | Key | Default | Extra |+------------+--------------+------+-----+---------+----------------+| id | int(11) | NO | PRI | NULL | auto_increment || cust_name | varchar(100) | NO | | NULL | || cust_addr | varchar(180) | NO | | NULL | || cust_phone | int(11) | YES | | NULL | || cust_email | varchar(90) | YES | | NULL | |+------------+--------------+------+-----+---------+----------------+5 rows in set (0.07 sec) Here is a visualI need this to go here and be reflected here via $_SESSION['id'] Quote Link to comment Share on other sites More sharing options...
WebStyles Posted February 27, 2014 Share Posted February 27, 2014 I like you 'question asking' skills with all the images and arrows... A bit overkill, but still fun. I would really like to help you, but there are so many things wrong with your code that I wouldn't know where to start. I will focus only on your issue: when you do your query loop : foreach($result as $item) { echo '<option value='.$item['id'].'>'; echo ($item['cust_name'] .",". $item['cust_addr'] .",". $item['cust_phone'] .",". $item['id']."<br />\n"); echo '</option>'; $_SESSION['id'] = $item['id']; } you have placed $_SESSION['id'] = $item['id']; inside the loop, that means $_SESSION['id'] keeps getting replaced with the next value. I really have to ask this though: If your <option> element has the customer id as it's value, that's the point of trying to store the id in the session too? When the form is submitted, you can grab the id and then place it in the session variable. Also, on your next page where you check for $_POST['id'], keep in mind that the name of your <select> element is bolredir and not id. Hope this helps Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.