php


Script keeps showing array to string conversion mistake


I created an array and stored it inside a $_SESSION variable, now I want to include that array inside a MySQL select statement to get more infos depending on p, which is included in my URL. My code is included inside a HTML page, which is completely empty except for necessary HTML and of course session_start, so this is not the problem. The code looks like that:
<?php
$p = $_GET["p"];
var_dump($_SESSION['questions'][$p]);
include("../script/db_connect.php");
$p = $_GET["p"];
$select_right_question = "select * from questions where id = '{$_SESSION['questions'][$p]}'";
$question_infos = mysqli_query($con, $select_right_question);
while ($row = mysqli_fetch_assoc($question_infos)) {
echo $row["question"] . '</br>'
. $row["right_answer"] . '</br>'
. $row["answer2"] . '</br>'
. $row["answer3"] . '</br>'
. $row["answer4"];
}
mysqli_close($con);
?>
I already tested it and the main issue is the following line:
$select_right_question = "select * from questions where id = '{$_SESSION['questions'][$p]}'";
What is the correct way to include the SESSION variable here?
Disregarding the security issues with your code, and assuming $_SESSION['questions'][$p] is returning an array, you can modify your SQL statement to:
$select_right_question = "select * from questions where id = '{$_SESSION['questions'][$p]['id']}'";

Related Links

How to fetch data from my database into <td id=“myId”> using php?
From project without framework to zend framework 2
Text Processing with PHP
Parameters merging with mod_rewrite
Symfony2 Sending RedirectResponse from Before Filter
Silex/Twig : Conflict between a custom filter and form widget
Unable to restart apache2 server on ubuntu 14.04
insert magento single product with list view on custom page
Recursive foreach loop (I think)
How to make a dropDownList in Yii?
mysqli::query(): MySQL server has gone away - php and mysql
MySQLI - INSERT or UPDATE on duplicate, multiple users
How to fetch all unread mail with attachment as an array ? i am using following code
If statement within Wordpress
Is there any reason to use the “public” keyword before method and member variable names? [duplicate]
Get URL variable in twig

Categories

HOME
android-studio
macos-sierra
opencart
tomcat
windows-8.1
kendo-dropdown
paypal-ipn
writefile
adobe
autocomplete
swift2
position
onvif
polymer-2.x
eddystone
lc3
lapack
responsivevoice
google-awareness
jpa-2.0
nest-api
closures
maven-plugin
pst
multi-upload
ava
sipp
ruby-daemons
onchange
bitbake
amazon-iam
es6-modules
vcenter
osx-lion
serversocket
creation
dreamfactory
pdfnet
xll
hidden-markov-models
right-click
grails-spring-security
raytracing
httphandler
code-push
destroy
viewmodel
sony-future-lab-n
nothing
password-hash
extjs4.1
.when
degrees
sidewaffle
boost-compute
scheduledexecutorservice
metabase
s-function
perforce-integrate
ajaxmin
apache-pig-grunt
frame-grab
xcopy
onepage-checkout
textpattern
lowercase
pythonxy
gluon-desktop
enaml
maven-shade-plugin
image-rotation
smacss
zend-mail
nesper
storing-data
relationships
xcode6.3.1
tabletools
oxygene
saga
discovery
ggts
apache-shindig
sql-view
jbox2d
significant-digits
towers-of-hanoi
wndproc
coordinate
trialware
getopts
fork-join
kext
jquery-1.4
cassini
uninstaller
activestate
android-input-method
cleartype
yahoo-maps
server-load
watchpoint
downloadfile

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App