doddsey_65 Posted July 25, 2011 Share Posted July 25, 2011 I am getting the error Attempt to assign property of non-object when uploading my code to the server. Everything works fine locally however. The error is generated because i have an object $data. I then assign a new property and value using $data->error = 'some error'; but my live server doesnt seem to like this. Is this normal behaviour? is there a workaround for this? my localhost is running php 5.3 and the live server is using 5.2 if that helps. Link to comment https://forums.phpfreaks.com/topic/242763-attempt-to-assign-property/ Share on other sites More sharing options...
wildteen88 Posted July 25, 2011 Share Posted July 25, 2011 Could you post your code here (within or tags). Link to comment https://forums.phpfreaks.com/topic/242763-attempt-to-assign-property/#findComment-1246874 Share on other sites More sharing options...
doddsey_65 Posted July 25, 2011 Author Share Posted July 25, 2011 sure but the object is generated via JSON so i will post the javascript object too. JS object: var data = { 'post': [ {subject : asf.getInput('subject')}, {content : asf.getInput('post_content')}, {forum_id : '{FORUM_ID}'}, {topic_id : '{TOPIC_ID}'} ] } and the php $data = json_decode($_POST['data']); add_post('topic',$data); function add_post($method, $data) { $db = db_pdo::$instance; $user = sessionsClass::$data; if(empty($data->post[0]->subject)) { $data->post[0]->subject = 'No Subject'; } if(empty($data->post[1]->content)) { $data->error = 'You must supply a message body'; } if($method == 'topic') { // sql for topic insertion $sql = "INSERT INTO ".TBL_PREFIX."topics (t_fid, t_name, t_poster, t_time_posted, t_last_poster, t_last_post_time) VALUES (:forum_id, :subject, :poster, :time, :last_poster, :last_post_time)"; // prepare the sql statement $sth = $db->prepare($sql); // execute the sql statement $sth->execute(array( ':forum_id' => $data->post[2]->forum_id, ':subject' => $data->post[0]->subject, ':poster' => $user['u_username'], ':time' => time(), ':last_poster' => $user['u_username'], ':last_post_time' => time() ) )or die($db->printError($sql)); if(empty($data->error)) { $data->success = 'Your topic has been created'; } echo json_encode($data); * removed some code to shorten(just queries) as you can see error and success dont appear in the original object so i add them, but the live server isnt liking this. Link to comment https://forums.phpfreaks.com/topic/242763-attempt-to-assign-property/#findComment-1246880 Share on other sites More sharing options...
doddsey_65 Posted July 25, 2011 Author Share Posted July 25, 2011 heres a dump of the javascript object if it helps: data 'post' 0 subject => 'test' 1 content => 'content' 2 forum_id => 1 3 topic_id => 1 Link to comment https://forums.phpfreaks.com/topic/242763-attempt-to-assign-property/#findComment-1246891 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.