Can't seem to figure out this php error -
i've been trying figure out php error day. sigh. i'm new coding thought had figured out. when run code, error
parse error: syntax error, unexpected 'body' (t_string), expecting ')' in /users/baronjon/sites/squaredb/functions.php on line 20
and here code:
<?php function add_post($userid, $body) { $sql = "insert posts (user_id, body, stamp) values ($userid, '". mysql_real_escape_string($body)."', now())"; $result = mysql_query($sql); } function show_posts($userid) { $posts = array(); $sql = "select body, stamp posts user_id ='$userid' order stamp desc"; $result = mysql_query($sql); while($data = mysql_fetch_object($result)) { $posts[] = array( 'stamp' => $data->stamp, 'userid => $userid 'body' => $data->body //**this line 20.** ); } return $posts; } ?> being new php (and coding in general) realize simple. don't see parenthesis it's telling me for.
i looked in php manual make sure had syntax correct , seem pretty straightforward.
can point me in right direction.
in $posts array missing trailing ' quote, , comma.
$posts array should like:
$posts[] = array( 'stamp' => $data->stamp, 'userid' => $userid, 'body' => $data->body //**this line 20.** ); many times in php, when says line 20, should looking @ line 19.
as commenter above mentioned recommend using code editor syntax highlighting vim, emacs, sublime text, notepad++ or similar. saves butt every day :).
Comments
Post a Comment