ohdang888 Posted January 2, 2008 Share Posted January 2, 2008 is this valid? $new_link = '<a href="game.php?title={$_POST["title"]}">$_POST["title"]</a>'; Quote Link to comment https://forums.phpfreaks.com/topic/84186-correct-variable/ Share on other sites More sharing options...
trq Posted January 2, 2008 Share Posted January 2, 2008 Depends what you want it to do. Syntax wise there are no errors, it probably won't do what you want though. More than likely your looking for.... $new_link = "<a href='game.php?title={$_POST['title']}'>{$_POST['title']}</a>"; Variables are not interpolated within single quoted strings. Quote Link to comment https://forums.phpfreaks.com/topic/84186-correct-variable/#findComment-428591 Share on other sites More sharing options...
hitman6003 Posted January 2, 2008 Share Posted January 2, 2008 Don't use single quotes...using single quotes php won't place the variable's value in it's place. For example: $var1 = 'abc'; $var2 = 'def'; echo 'var1 is $var1 and var2 is $var2'; //you get "var1 is $var1 and var2 is $var2" echo "var1 is $var1 and var2 is $var2"; //you get "var1 is abc and var2 is def" And, what thorpe said...( beat me to it ) Quote Link to comment https://forums.phpfreaks.com/topic/84186-correct-variable/#findComment-428594 Share on other sites More sharing options...
AV1611 Posted January 2, 2008 Share Posted January 2, 2008 Maybe I'm being too cautious but I would do this: if(!isset($_POST['title'])){ //something} else { $title=$_POST['title']; } $new_link = '<a href="game.php?title='.$title.'">'.$title.'</a>'; Quote Link to comment https://forums.phpfreaks.com/topic/84186-correct-variable/#findComment-428597 Share on other sites More sharing options...
ohdang888 Posted January 2, 2008 Author Share Posted January 2, 2008 what i am doign with this code is inserting $new_link into a databse. the variable code i gave earlier wasn;'t working. only i will have access to the page, so i don't need to worry about injections with this code either Quote Link to comment https://forums.phpfreaks.com/topic/84186-correct-variable/#findComment-428605 Share on other sites More sharing options...
ohdang888 Posted January 2, 2008 Author Share Posted January 2, 2008 i am getting this error when i clcik submit Error in query: . 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 'game.php?title=angry'>angry', 'afsdadsf', 'asdfh', 'gggg', 'gggg', 'ggg', ' at line 2 this is where the prpoblem is $title= $_POST["title"]; $new_link = "<a href='game.php?title={$title}'>{$title}</a>"; whats the matter with it.??? Quote Link to comment https://forums.phpfreaks.com/topic/84186-correct-variable/#findComment-428621 Share on other sites More sharing options...
hitman6003 Posted January 2, 2008 Share Posted January 2, 2008 You need to escape the single quotes in your mysql query...use mysql_real_escape_string $new_link = mysql_real_escape_string("<a href='game.php?title={$title}'>{$title}</a>"); http://www.php.net/mysql_real_escape_string Quote Link to comment https://forums.phpfreaks.com/topic/84186-correct-variable/#findComment-428630 Share on other sites More sharing options...
ohdang888 Posted January 2, 2008 Author Share Posted January 2, 2008 Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampp\htdocs\newcreate.php on line 4 Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in C:\xampp\htdocs\newcreate.php on line 4 ahhhhhhhhhhhhhhhhhhhhhhhhhhhhhh. any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/84186-correct-variable/#findComment-428727 Share on other sites More sharing options...
teng84 Posted January 2, 2008 Share Posted January 2, 2008 it is bad idea to put the whole codes in your DB just put there the location or maybe just the title which only dydnamic putting whole tags is crazy lol Quote Link to comment https://forums.phpfreaks.com/topic/84186-correct-variable/#findComment-428730 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.