maplematt;11034541 wrote:
Print_r ($_SESSION);
output of printing the session:
Array ( [user] => Array ( [id] => 2 [username] => nonadmintest [email] => help@ge.com [admin] => 0 ) [admin] => Array ( [id] => 2 [username] => nonadmintest [email] => help@ge.com [admin] => 0 ) ) Failed to run query: SQLSTATE[21S01]: Insert value list does not match column list: 1136 Column count doesn't match value count at row 1
So from this I can tell my checkbox selections are not being added to the session(?)
Most likely. All you can say for sure is "not at that point".
Going back to your previous post, you had
<submitb>
<?
session_start();
$_SESSION['country']=$country;
$_SESSION['serv']=$serv;
$_SESSION['apps']=$apps;?>
<input type="submit" value="Update">
</submitb>
</form>
Then on my retrieval end:
I was obviously not paying enough attention the first time I replied. Among other things I missed that we are not looking at HTML code… Taking a second look at it, I'm starting to wonder if you've missunderstood the difference between what happens on the server, what happens in the client and how the two relate. Anyway, for now I will assume we are dealing with html code and a web browser, until otherwise specified.
Looking at the above, you have php code between what seems to imply a submit button, while the code in that place doen'st output text to produce a submit button, but rather seems to be php code meant to deal with receiving the post request. And after that you write "then on my retrieval end". But receiving the form data would actually be that "retrieval end".
The way it works is
- [Client] requests the form
- [Server] Either you have an html document with the form, or you have PHP code which produces the exact same html document as output. Either way, the exact same thing would be sent by the server. Whatever is sent from the server to the client is nothing but text.
3.1 [Client]Recieves your document. If it's sent as an html document, the text will be processed as such and turned from text into form elements etc. But the browser does not understand php code, it has no php parser. Which doesn't really matter. Look at the document source (rclick the page in your browser, and click "show source" or similar). It contains no php tags (remember those are handled in step 2)
3.2 [Client] When user is done and clicks submit, the browser performs the duty of assembling the form data in some agreed-upon form, either implicit default or explicit form attribute. Another request is sent to the server, which is the same thing that happens in step 1, except another resource is requested, or the server decides to do other things based on the form being submitted etc, so let's look at it as if it's not already looping back to step 1.
- [Server] Receives data, and the web server + php will populate $GET (url query string) and $POST (the body of a post request) arrays with such data.
- [Server] At this point, you may take user input and store it in $_SESSION for later use. The server may produce more output, such as an html document and send it to the browsers…
If my suspicion is correct, you are trying to perform step 5 during step 2. Moreover, because of this missunderstanding, you are trying to propagate things from step 2 to 5 using session data, when in reality you don't need any special handling of it. It will arrive by means of post or get data. Only if you need to propagate data from to subsequent page requests will you need to use sessions.
First request is for show-form.php
show-form.php
session_start();
echo $the-form-document;
Whatever resource pointed to by the previous form's action attribute. It could even be the same script again, i.e.e "show-form.php", but let's say it's "process-form.php" instead.
process-form.php
session_start();
# the page could be requested as a GET request, or without the form we wish to deal with being sent. Perform some check that you get what you want
if (!isset($_POST['submit'])) {
# location always takes a fully qualified url - including protocol specification - http, https etc
header('location: http://example.com/show-form.php');
exit;
}
if (isset($_POST['app'])) {
# deal with this as you need - you have received the data. no need for sessions…
printf('You selected the following: %s%s',
'<br>',
implode(', ', $_POST['app'])
);
# … unless you want to use the data on future page requests
# BUT! Do note that you can _only_ store strings as session data - look up serialize and unserialize at php.net
$_SESSSION['app'] = serialize($_POST['app']);
}
User now clicks any other link, types in a url or whatever which takes them to the same domain for which the session is valid
start.php
session_start();
# but here you cannot necessarily know that the user has made his selection yet.
if (empty($_SESSION['app'])) {
printf('No seletion made so far. <a href="%s">One man enter, two choices made here!</a>',
'/show-form.php'
);
}
else {
printf('Your selection is: %s',
implode(', ', unserialize($_SESSION['app']))
);
}
If you can't immediately manage to transform the above into your own usecase, go ahead and make the three pages I suggested while keeping them as simple as possible. Once you have them working you should understand the logic and be able to implement it in your own case.
maplematt;11034541 wrote:
I am trying to split the array into each individual elements and store them in the db individually.
And once again, if this is all you need, why bother with sessions to begin with? Data is posted -> process incoming data and store in db.