TheCatapult Posted March 10, 2012 Share Posted March 10, 2012 Please help me. I got this error in my php file Parse error: syntax error, unexpected T_STRING in /srv/disk4/741839/www/catapultphpmysql.eu.pn/insert.php on line 11 here's the code <?phpinclude_once('resource/init.php');if ( isset($_POST['title'], $_POST['post']) ){ mysql_query("INSERT INTO `posts` SET `title` = `{$_POST['title']} `contents` = `{$_POST['post']}}//$q = mysql_query("SELECT `contents` FROM `posts` WHERE `id` = '4');//$r = mysql_fetch_assoc($q);////echo $r['contents'];?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head> <title>Add a post!</title> <meta http-equiv="content-type" cotnent="text/html; charset=utf-8 /> <style type="text/css> label {display: block; } </style></head><body> <div id="main"> <form method="post" action=""> <div> <label for="title">Ttile:</label> <input type=text" name "title" id="title" /> </div> <label for="post">Post:</label> <textarea name="post" id="post" rows="15" cols="50"></textarea> </div> <div> <input type="submit" value="Post" /> </div> </form> </div></body></html> thnx Link to comment Share on other sites More sharing options...
birbal Posted March 10, 2012 Share Posted March 10, 2012 //$q = mysql_query("SELECT `contents` FROM `posts` WHERE `id` = '4');you are not closing the quotes here //$q = mysql_query("SELECT `contents` FROM `posts` WHERE `id` = '4'"); and your insert quryy also missing a 'tick',closing quote and closing paren. Link to comment Share on other sites More sharing options...
TheCatapult Posted March 10, 2012 Author Share Posted March 10, 2012 Hi! I found another problem! Parse error: syntax error, unexpected '`' in /home/a2133468/public_html/insert.php on line 6 Here's the new code <?phpinclude_once('resource/init.php');if ( isset($_POST['title'], $_POST['post']) ){ mysql_query("INSERT INTO") `posts` SET `title` = `{$_POST['title']} `contents` = `{$_POST['post']}}//$q = mysql_query("SELECT") `contents` FROM `posts` WHERE `id` = '4');//$r = mysql_fetch_assoc($q);////echo $r['contents'];?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head> <title>Add a post!</title> <meta http-equiv="content-type" cotnent="text/html; charset=utf-8 /> <style type="text/css> label {display: block; } </style></head><body> <div id="main"> <form method="post" action=""> <div> <label for="title">Ttile:</label> <input type=text" name "title" id="title" /> </div> <label for="post">Post:</label> <textarea name="post" id="post" rows="15" cols="50"></textarea> </div> <div> <input type="submit" value="Post" /> </div> </form> </div></body></html> Thanks! Link to comment Share on other sites More sharing options...
birbal Posted March 10, 2012 Share Posted March 10, 2012 mysql_query("INSERT INTO `posts` SET `title` = '{$_POST['title']}[b]'[/b] `contents` = '{$_POST['post']}'") that error means it is syntactical error. you had missed paren and quotes.backtick is used in column name to avoid amgation in mysql reserved words and column,table,database names.you should use single quote around strings. Link to comment Share on other sites More sharing options...
TheCatapult Posted March 10, 2012 Author Share Posted March 10, 2012 I got this problem, again when I changed it to what you said. Parse error: syntax error, unexpected T_STRING in /home/a2133468/public_html/insert.php on line 11 Link to comment Share on other sites More sharing options...
birbal Posted March 10, 2012 Share Posted March 10, 2012 post your updated code Link to comment Share on other sites More sharing options...
TheCatapult Posted March 10, 2012 Author Share Posted March 10, 2012 maybe there really a major problem in my code <?phpinclude_once('resource/init.php');if ( isset($_POST['title'], $_POST['post']) ){ mysql_query("INSERT INTO `posts` SET `title` = `{$_POST['title']} `contents` = `{$_POST['post']}}//$q = mysql_query("SELECT") `contents` FROM `posts` WHERE `id` = '4');//$r = mysql_fetch_assoc($q);////echo $r['contents'];php?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head> <title>Add a post!</title> <meta http-equiv="content-type" cotnent="text/html; charset=utf-8 /> <style type="text/css> label {display: block; } </style></head><body> <div id="main"> <form method="post" action=""> <div> <label for="title">Ttile:</label> <input type=text" name "title" id="title" /> </div> <label for="post">Post:</label> <textarea name="post" id="post" rows="15" cols="50"></textarea> </div> <div> <input type="submit" value="Post" /> </div> </form> </div></body></html> Link to comment Share on other sites More sharing options...
boen_robot Posted March 10, 2012 Share Posted March 10, 2012 I don't think you got birbal's point... when you open a string with a " you need another " to end the string with.Look at this part of your code: if ( isset($_POST['title'], $_POST['post']) ){ mysql_query("INSERT INTO `posts` SET `title` = `{$_POST['title']} `contents` = `{$_POST['post']}}//$q = mysql_query(" Tell me, from PHP's point of view, what strings are there? Where does each one start and end? You'll notice one of them doesn't end where you probably expect it to. Link to comment Share on other sites More sharing options...
TheCatapult Posted March 10, 2012 Author Share Posted March 10, 2012 Look at what happen Parse error: syntax error, unexpected '`' in /home/a2133468/public_html/insert.php on line 6 <?phpinclude_once('resource/init.php');if ( isset($_POST['title'], $_POST['post']) ){ mysql_query("INSERT INTO" `posts` SET `title` = `{$_POST['title']} `contents` = `{$_POST['post']}}//$q = mysql_query("SELECT") `contents` FROM `posts` WHERE `id` = '4');//$r = mysql_fetch_assoc($q);////echo $r['contents'];php?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head> <title>Add a post!</title> <meta http-equiv="content-type" cotnent="text/html; charset=utf-8 /> <style type="text/css> label {display: block; } </style></head><body> <div id="main"> <form method="post" action=""> <div> <label for="title">Ttile:</label> <input type=text" name "title" id="title" /> </div> <label for="post">Post:</label> <textarea name="post" id="post" rows="15" cols="50"></textarea> </div> <div> <input type="submit" value="Post" /> </div> </form> </div></body></html> Many thank Link to comment Share on other sites More sharing options...
boen_robot Posted March 10, 2012 Share Posted March 10, 2012 For f**k's sake... <?phpinclude_once('resource/init.php');if ( isset($_POST['title'], $_POST['post']) ){ mysql_query("INSERT INTO `posts` SET `title` = `{$_POST['title']} `contents` = `{$_POST['post']}");}//$q = mysql_query("SELECT") `contents` FROM `posts` WHERE `id` = '4');//$r = mysql_fetch_assoc($q);////echo $r['contents'];?> From PHP's point of view, your whole query is one string => You must have the query surrounded with " . Link to comment Share on other sites More sharing options...
TheCatapult Posted March 11, 2012 Author Share Posted March 11, 2012 Thank you boen_robot! Sadly, what I put and send in this form do not sent in phpmyAdmin. Here's the code of my files. (They are in 'resource' folder) init.php <?include_once('config.php');mysql_connect(DB_HOST, DB_USER, DB_PASS);mysql_select_db(DB_NAME);?> config.php <?$config['db_host'] = 'XXXXXXXXXX';$config['db_user'] = 'XXXXXXXXXXX';$config['db_pass'] = 'XXXXXXXXXX';$config['db_name'] = 'XXXXXXXXXXX';foreach ( $config as $k => $v ) { define(strtoupper($k), $v);}?> Link to comment Share on other sites More sharing options...
birbal Posted March 11, 2012 Share Posted March 11, 2012 the query does not goes in phpmyadmin it actualy goes to mysql server. if you are unsure why your query is not working you can always use mysql_error() when you use mysql_connect() check its return value that it succefully returning or not else echo the mysql_error(). do same with mysql_query(). check the manual page of phphttp://php.net/mysql_query <?$config['db_host'] = 'XXXXXXXXXX';$config['db_user'] = 'XXXXXXXXXXX';$config['db_pass'] = 'XXXXXXXXXX';$config['db_name'] = 'XXXXXXXXXXX';foreach ( $config as $k => $v ) { define(strtoupper($k), $v);}?>and you can directly assign it as constant without looping the array. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.