Jump to content

Parse error: syntax error, unexpected T_STRING in /srv/disk4/741839/www/catapultphpmysql.eu.pn/insert.php on line 11


TheCatapult
 Share

Recommended Posts

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

Edited by MisterCatapult
Link to comment
Share on other sites

//$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.

Edited by birbal
Link to comment
Share on other sites

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

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

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

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

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

Edited by MisterCatapult
Link to comment
Share on other sites

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

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);}?>

Edited by MisterCatapult
Link to comment
Share on other sites

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...