cloudy243 Posted April 5, 2009 Share Posted April 5, 2009 When i try to insert some variables into a mysql database from php php code: $sql="INSERT INTO posts (user, post, order) VALUES ('$name','$post_put','$num')"; I get this error: Error, please report to harris(webmaster): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order) VALUES ('harris',' test ','2')' at line 1 if i use this code: $sql="INSERT INTO posts (user, post) VALUES ('$name','$post_put'')"; it works. can someone please tell me what i am doing wrong when i add on order. Yes the order columb in the mysql db is made and if i echo $num i get the number i want to go into the database, just something is wrong when it tries to put the # into the db Quote Link to comment https://forums.phpfreaks.com/topic/152613-solved-error-with-posting-from-php-to-mysql/ Share on other sites More sharing options...
xtopolis Posted April 5, 2009 Share Posted April 5, 2009 ORDER is a reserved word. `order` for a quick fix. but to rename the column to something such as position Quote Link to comment https://forums.phpfreaks.com/topic/152613-solved-error-with-posting-from-php-to-mysql/#findComment-801513 Share on other sites More sharing options...
cloudy243 Posted April 5, 2009 Author Share Posted April 5, 2009 ok thanks for the help it worked also now i have a new problem. I am making a website where i want some areas to ignore html/php and just display the code, so i put <xmp> </xmp> around the code, but i want to still allow <br />'s. without going <xmp> code </xmp><br /> <xmp> morecode </xmp> is there a way i can have php search the file and replace <br /> with </xmp> <br /> <xmp> so i dont have to type extra lol. the <xmp> code <br /> morecode </xmp> is displayed using echo "$post"; Quote Link to comment https://forums.phpfreaks.com/topic/152613-solved-error-with-posting-from-php-to-mysql/#findComment-801517 Share on other sites More sharing options...
xtopolis Posted April 5, 2009 Share Posted April 5, 2009 I'm not familiar with "<xmp>", but if it's stored in a variable like $post, you could search and replace "<br />" with "& lt;br /& gt;" (without the spaces)... perhaps? Quote Link to comment https://forums.phpfreaks.com/topic/152613-solved-error-with-posting-from-php-to-mysql/#findComment-801524 Share on other sites More sharing options...
cloudy243 Posted April 5, 2009 Author Share Posted April 5, 2009 how do i have it search and replace? Quote Link to comment https://forums.phpfreaks.com/topic/152613-solved-error-with-posting-from-php-to-mysql/#findComment-801714 Share on other sites More sharing options...
xtopolis Posted April 5, 2009 Share Posted April 5, 2009 The same way they do BB code, http://www.tutorio.com/tutorial/simple-and-complex-bbcode-with-php/ Quote Link to comment https://forums.phpfreaks.com/topic/152613-solved-error-with-posting-from-php-to-mysql/#findComment-801743 Share on other sites More sharing options...
cloudy243 Posted April 5, 2009 Author Share Posted April 5, 2009 so for example if i have the following script <?php $post = " <xmp> Welcome to ForumZ <br /> We host your forums! <br /> Have a nice day!!! </xmp>"; echo $post; ?> how would i make it find the <"br />" and replace them with "</xmp> <br /> <xmp>" without the quotes. You dont really need to know what <xmp> is, i just need to know how to make it find and replace in the code. Quote Link to comment https://forums.phpfreaks.com/topic/152613-solved-error-with-posting-from-php-to-mysql/#findComment-801801 Share on other sites More sharing options...
cloudy243 Posted April 5, 2009 Author Share Posted April 5, 2009 for those of you who dont know anything in <xmp> </xmp> will have it's html ignored, so if you are writting a website or something you can show coding by saying <xmp> <br /> </xmp> and on a normal website you wont see a line down but instead the code Quote Link to comment https://forums.phpfreaks.com/topic/152613-solved-error-with-posting-from-php-to-mysql/#findComment-801850 Share on other sites More sharing options...
xtopolis Posted April 6, 2009 Share Posted April 6, 2009 Replace them with "\n" for line breaks. The double quotes are important for \n Quote Link to comment https://forums.phpfreaks.com/topic/152613-solved-error-with-posting-from-php-to-mysql/#findComment-801909 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.