php - Call to a member function attributes() on a non-object on line 7 -
okay guys, have searched reply of problem everywhere had no luck in solving problem. created xml document named questions.xml. sample of codes i.e
<quiz> <topic text="preparation exam"> <subtopic text="science"> <question text="what largest planet in our solar system?"> <answer num = "a" text="jupiter" correct="1"></answer> <answer num = "b" text="venus" correct="0"></answer> <answer num = "c" text="saturn" correct="0"></answer> <answer num = "d" text="mars" correct="0"></answer> </question> <question text="what smallest planet?" > <answer num = "a" text="pluto" correct="1"></answer> <answer num = "b" text="venus" correct="0"></answer> <answer num = "c" text="saturn" correct="0"></answer> <answer num = "d" text="mars" correct="0"></answer> </question> </subtopic> </topic> </quiz>
then made form info shows different question numbers , have select 1 question. used radio buttons selection , defined submit button named "question". when user selects , submits question radio button values either 0,1,2,3 etc passed php page via post method. in new php page have show desired question in text fieldarea. problem stupid error "call fellow member function attributes() on non-object on line 6". codes
<?php $condition= $_post['question']; $xml = simplexml_load_file("questions.xml"); echo $condition; if ($condition=="0"){ $question= $xml-> topic -> subtopic-> question[$condition] -> attributes()-> text."<br>"; echo "<form action='' method='post'> <label for='question'> question</label> <textarea name='question' id='1' cols='45' rows='5'>".$question."</textarea> <p><input type=submit value='submit'> </form>"; } ?>
now there no syntax error, , programme displaying echo $condition , not displaying question displays "call fellow member function attributes() on non-object on line 6". pissed ..kindly help me.
$xml-> topic -> subtopic-> question[0]
exists , $xml-> topic -> subtopic-> question["0"]
doesn't.
casting $_post['question']
integer trick.
$condition= (int) $_post['question'];
would work.
php xml simplexml
No comments:
Post a Comment