corrupshun Posted November 30, 2009 Share Posted November 30, 2009 How can i store all of this in varible $gamecode (idk how to put php code in variables) $nothing = ""; $list = range(1,2); if(!isset($_GET['gameid'])) { include("inc/defaultgame.php"); } elseif($_GET['gameid'] == $nothing){ include("inc/defaultgame.php"); } elseif(in_array($_GET['gameid'], $list) === false) { echo('Invalid GameID'); } else { $con = mysql_connect("localhost","root",""); mysql_select_db("Corrupshun", $con); $query = mysql_query("SELECT Title, Path FROM Games WHERE id = $_GET[gameid]"); while($row = mysql_fetch_assoc($query)) { $gamepath = $row['Path']; $gametitle = $row['Title']; } } This is probably a really dumb question Quote Link to comment https://forums.phpfreaks.com/topic/183365-how-can-i-put-php-code-in-a-variable/ Share on other sites More sharing options...
mikesta707 Posted November 30, 2009 Share Posted November 30, 2009 if its in a file you can use something like $code = file_get_contents("path/to/file"); you could also just surround it with quotes. Make sure to escape any quotes inside the code Quote Link to comment https://forums.phpfreaks.com/topic/183365-how-can-i-put-php-code-in-a-variable/#findComment-967870 Share on other sites More sharing options...
corrupshun Posted November 30, 2009 Author Share Posted November 30, 2009 what do you mean by escape any quotes? Quote Link to comment https://forums.phpfreaks.com/topic/183365-how-can-i-put-php-code-in-a-variable/#findComment-967872 Share on other sites More sharing options...
mikesta707 Posted November 30, 2009 Share Posted November 30, 2009 what ever type of quote you surround any string with (" or ') you need to escape any occurrences of that character inside the string with the escape character (\) for example this is good $string = "he said \"hey\" to me!"; //more code bad $string = 'my name is o'neil'; //more code notice the difference in syntax highlighting. Quote Link to comment https://forums.phpfreaks.com/topic/183365-how-can-i-put-php-code-in-a-variable/#findComment-967874 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.