recset Posted September 10, 2006 Share Posted September 10, 2006 I have the following problem, I am trying to store a php path in a SQL table (the field is a 'TEXT' field), db structure is latin2.Here is the short path that i am trying to store ([b]the code is actually a parameter for a link[/b]):[code]wisdom2.php?MAXIMID=<?php echo $row_menu['ID']; ?>[/code]However, I get this error message when I try to run a page that tries to extract the php code:[code]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 BY AUTHOR ASC' at line 1[/code]Now, if I were to simply write the same piece of code in a php page, it works fine, does anyone have an answer to why it is not working when the piece of code is stored in a SQL Database?(Pls don't respond w/ the obvious answer, ;) I need it to be this way for a reason .... )Thank you, Quote Link to comment https://forums.phpfreaks.com/topic/20328-storing-php-syntax-variables-in-sql/ Share on other sites More sharing options...
HuggieBear Posted September 10, 2006 Share Posted September 10, 2006 Do you mean this is in your SQL statement, similar to this:[code=php:0]$sql = "INSERT INTO table (path) VALUES ('wisdom2.php?MAXIMID=<?php echo $row_menu['ID']; ?>')";[/code]If so, then it's because of the single quotes around 'ID'. Have you tried to use htmlentities() on the string first of all, that works?That would insert:[code]wisdom2.php?MAXIMID=<?php echo $row_menu['ID']; ?>[/code]Or just escaping the single quotes by doubling them up, like so:[code=php:0]$sql = "INSERT INTO table (path) VALUES ('wisdom2.php?MAXIMID=<?php echo $row_menu[''ID'']; ?>')"; // notice two single quotes around ID[/code]Let me know how you get on.Rich Quote Link to comment https://forums.phpfreaks.com/topic/20328-storing-php-syntax-variables-in-sql/#findComment-89556 Share on other sites More sharing options...
recset Posted September 11, 2006 Author Share Posted September 11, 2006 Actually its not a Select statement, its actually meant to be added as a url parameter after an existing link.For example on the page wisdom2.php, there is a link:[code]www.blanksite.com/URL PARAMETER here[/code]The URL PARAMETER, is brought from the database which i am trying to get working. Quote Link to comment https://forums.phpfreaks.com/topic/20328-storing-php-syntax-variables-in-sql/#findComment-89813 Share on other sites More sharing options...
Jenk Posted September 11, 2006 Share Posted September 11, 2006 what is in the db and what is the final result you are looking for?Please post exacting examples, not descriptions :)e.g.: In the column 'column', the value is:[code]xyz[/code]I would like to output:[code]abc[/code] Quote Link to comment https://forums.phpfreaks.com/topic/20328-storing-php-syntax-variables-in-sql/#findComment-89816 Share on other sites More sharing options...
recset Posted September 11, 2006 Author Share Posted September 11, 2006 Sorry, about that.Ok, in the db is: [code]'wisdom2.php?MAXIMID=<?php echo $row_menu['ID']; ?>[/code]What I want the final result is to change the url of the browser window (when clicked) to:[code]'wisdom2.php?MAXIMID=<?php echo $row_menu['ID']; ?>[/code]the php tag would actually be a number of a recordset (depending on the row menu).Thus, that output would be something like:[code]'wisdom2.php?MAXIMID=5[/code] Quote Link to comment https://forums.phpfreaks.com/topic/20328-storing-php-syntax-variables-in-sql/#findComment-89877 Share on other sites More sharing options...
recset Posted September 16, 2006 Author Share Posted September 16, 2006 [b]Can anyone help out with this problem???? Please Help, thank you!!![/b] Quote Link to comment https://forums.phpfreaks.com/topic/20328-storing-php-syntax-variables-in-sql/#findComment-93018 Share on other sites More sharing options...
Daniel0 Posted September 16, 2006 Share Posted September 16, 2006 Change it to: [code]'wisdom2.php?MAXIMID=%d[/code] then do this: [code]echo sprintf($the_thing_you_got_from_the_db,$row_menu['ID']);[/code] Quote Link to comment https://forums.phpfreaks.com/topic/20328-storing-php-syntax-variables-in-sql/#findComment-93082 Share on other sites More sharing options...
mainewoods Posted September 16, 2006 Share Posted September 16, 2006 when you have this error:[quote]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 BY AUTHOR ASC' at line 1[/quote]-it is always complaining about a mysql_query(); statement somewhere when you get that error statement. When it says line 1 like that, it usually means that the mysql_query() is located in an include file. The error is not caused by the code you presented. Is there an include coded in the first line of your source code?you should be able to search your source code for "ORDER BY AUTHOR ASC" and that will tell you the source code line the error occurred on. Quote Link to comment https://forums.phpfreaks.com/topic/20328-storing-php-syntax-variables-in-sql/#findComment-93207 Share on other sites More sharing options...
recset Posted September 17, 2006 Author Share Posted September 17, 2006 Mainewoods,I found the line:[code]$query_quotes = sprintf("SELECT * FROM wisdom_backup WHERE MAXIMID = %s ORDER BY AUTHOR ASC", $colname_quotes);[/code]The whole reason for this is to clear a url parameter that is added to the URL in the browser everytime a user 'votes' on a record. Thus, if the user doesn't vote, then this line is irrelevant. But, when the user 'votes' it adds a URL parameter to the browser, so that if the user decides to vote on another record, it will count 2 votes (1 for the new vote hit, and 1 for the previous vote hit, because each url parameter is now in the url shown in the browser). So essentially, after the user votes, I just want to clear the URL parameter.Does this make sense? Or am I over-thinking this? Quote Link to comment https://forums.phpfreaks.com/topic/20328-storing-php-syntax-variables-in-sql/#findComment-93325 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.