2

CONTROLLER FUNCTION CODE:

$surveydata = $this->getsurveydatabasedonId($SurveyId);
$this->load->view('editsurvey', array('surveydata' => $surveydata));

VIEW CODE:

   <h1 class="page-header">Edit Survey</h1>
                <?php
                $att = array('id' => 'editsurvey_form', 'role' => 'ajax-form');
                echo form_open('welcome/editsurvey', $att);
                ?>
                <div class="span5 offset1" id="form_div">
                    <?php echo validation_errors('<div class="alert alert-danger reg_error">', '</div>'); ?>
                    <div class="form-group control-group warning">
                        <input name="SurveyId" style="display:none" type="text" class="form-control" data-validation-required-message="Please enter a Survey Id" id="SurveyId" required placeholder="Please enter the Survey Id" value="<?php echo set_value('SurveyId', $surveydata->SurveyId); ?>">
                        <label for="SurveyTitle">Survey Title</label>
                        <input name="SurveyTitle" type="text" class="form-control" data-validation-required-message="Please enter a Survey Title" id="SurveyTitle" required placeholder="Please enter the Survey Title" value="<?php echo set_value('SurveyTitle', $surveydata->SurveyTitle); ?>">
                        <p class="help-block"></p>
                    </div>
                    <div class="form-group control-group warning">
                        <label for="SurveyIntroduction">Survey introduction</label>
                        <textarea name="SurveyIntro" type="text" class="form-control" id="SurveyIntro" placeholder="Enter the Survey Introduction"><?php echo set_value('SurveyIntro', $surveydata->SurveyIntro); ?></textarea>
                    </div>

                    <button type="submit" class="btn btn-large btn-warning">Edit Survey</button>
                </div>
                </form>

I am getting the following errors :

 A PHP Error was encountered

Severity: Notice

Message: Trying to get property of non-object

Filename: views/editsurvey.php

Line Number: 11

I am passing the array but it isn't working could someone help me please?

5
  • Is $surveydata contains the key surveydata in it in the controller ? Commented Apr 4, 2014 at 11:19
  • yes it does have put up the controller code as well Commented Apr 4, 2014 at 11:20
  • Can you check var_dump($surveydata); on top of your view file ?\ Commented Apr 4, 2014 at 11:21
  • array (size=1) 0 => array (size=7) 'SurveyId' => string '145' (length=3) 'SurveyTitle' => string 'Survey 6' (length=8) 'SurveyIntro' => string 'Survey 6' (length=8) 'CreatedBy' => string 'm123456789' (length=10) 'DateCreated' => string '2014-04-04 04:08:12' (length=19) 'isDisabled' => string '0' (length=1) 'SurveyLink' => string '21491' (length=5) Commented Apr 4, 2014 at 11:31
  • Access it using $surveydata[0]['SurveyTitle'] ? Commented Apr 4, 2014 at 11:37

2 Answers 2

1

Please make sure,

You have data in your $surveydata.

If you are fetching results through

$resultSet->result() OR $resultSet->row(), then use $surveydata->SurveyTitle

And if you are fetching the results through:

$resultSet->result_array() OR $resultSet->row_array(), then use $surveydata['SurveyTitle]

Also, please make sure to check count of $surveydata

Sign up to request clarification or add additional context in comments.

4 Comments

This is the data array (size=1) 0 => array (size=7) 'SurveyId' => string '145' (length=3) 'SurveyTitle' => string 'Survey 6' (length=8) 'SurveyIntro' => string 'Survey 6' (length=8) 'CreatedBy' => string 'm123456789' (length=10) 'DateCreated' => string '2014-04-04 04:08:12' (length=19) 'isDisabled' => string '0' (length=1) 'SurveyLink' => string '21491' (length=5)
I am fetching a row of data
Then, you should check num_rows().
Got it working thanks so much There was an issue with the row
1

It should be $surveydata[0]['SurveyId'], not $surveydata->SurveyId

Same for SurveyTitle It should be $surveydata[0]['SurveyTitle'], not $surveydata->SurveyTitle

6 Comments

Fatal error: Cannot use object of type stdClass as array in C:\wamp\www\surveytool\application\views\editsurvey.php on line 12 Call Stack #TimeMemoryFunctionLocation 10.0006264992{main}( )..\index.php:0 20.0017322600require_once( 'C:\wamp\www\surveytool\system\core\CodeIgniter.php' \
same mistake you have done on next line also. Please correct wherever you have used $surveydata->SurveyId
In controller what is the output when you do print_r($surveydata);
when i do var_dump i get this array (size=1) 0 => array (size=7) 'SurveyId' => string '145' (length=3) 'SurveyTitle' => string 'Survey 6' (length=8) 'SurveyIntro' => string 'Survey 6' (length=8) 'CreatedBy' => string 'm123456789' (length=10) 'DateCreated' => string '2014-04-04 04:08:12' (length=19) 'isDisabled' => string '0' (length=1) 'SurveyLink' => string '21491' (length=5)
Now check what happens?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.