YourNameHere Posted October 2, 2009 Share Posted October 2, 2009 I need to require() in a file but also need the url to be dynamic. This is what I have tried. $classfunction = $race . '-functions.php'; require($classfunction); $race = 'human'; is this simply not possible with the require function? Quote Link to comment https://forums.phpfreaks.com/topic/176332-solved-dynamic-requirement-of-include-file/ Share on other sites More sharing options...
Alex Posted October 2, 2009 Share Posted October 2, 2009 Of course that's possible. Maybe the problem with the code is that you're defining $race after it's used in the file's name? Quote Link to comment https://forums.phpfreaks.com/topic/176332-solved-dynamic-requirement-of-include-file/#findComment-929375 Share on other sites More sharing options...
YourNameHere Posted October 2, 2009 Author Share Posted October 2, 2009 I dumped my POST data and it shows that the $_POST['race'] is being populated. after echoing $race, it echos "Human" I dont think that is the issue. but when I echo $classfunction it says "-functions.php" Quote Link to comment https://forums.phpfreaks.com/topic/176332-solved-dynamic-requirement-of-include-file/#findComment-929377 Share on other sites More sharing options...
Alex Posted October 2, 2009 Share Posted October 2, 2009 Post your code, we can't help without seeing what you're doing wrong. Quote Link to comment https://forums.phpfreaks.com/topic/176332-solved-dynamic-requirement-of-include-file/#findComment-929379 Share on other sites More sharing options...
YourNameHere Posted October 3, 2009 Author Share Posted October 3, 2009 session_start(); require('../config.php'); $classfunction = $race . '-functions.php'; //require($classfunction); $con = mysql_connect($server, $db_user, $db_pass); mysql_select_db($db); // Insert into chars $sql = "Insert Into 'chars' (cname, class, owner, race) values ('$name', '$class', '$player', '$race')"; $result = mysql_query($sql); //Insert into CharStats $sql = "Insert Into 'charStats' (cname, dex, str, wis, int, con, cha, dexMod, strMod, wisMod, intMod, conMod, chaMod, ac, will, fort, ref, hp, speed, perception, init ) values ('$name', '$dex', '$str', '$wis', '$int', '$con', '$cha', '$dexMod', '$strMod', '$wisMod', '$intMod' '$conMod', '$chaMod', '$ac', '$will', '$fort', '$ref', '$hp', '$speed', '$perception', '$dexMod')"; // Set Variables $race= $_POST['race']; Quote Link to comment https://forums.phpfreaks.com/topic/176332-solved-dynamic-requirement-of-include-file/#findComment-929382 Share on other sites More sharing options...
Alex Posted October 3, 2009 Share Posted October 3, 2009 As I said before $race isn't defined before you use it. Do you mean: $classfunction = $_POST['race'] . '-functions.php'; ? Edit, just move your defining of $race to above where you're using it.. Quote Link to comment https://forums.phpfreaks.com/topic/176332-solved-dynamic-requirement-of-include-file/#findComment-929386 Share on other sites More sharing options...
trq Posted October 3, 2009 Share Posted October 3, 2009 $race is defined anywhere in that code. Quote Link to comment https://forums.phpfreaks.com/topic/176332-solved-dynamic-requirement-of-include-file/#findComment-929388 Share on other sites More sharing options...
YourNameHere Posted October 3, 2009 Author Share Posted October 3, 2009 Yes Thorpe, I saw that I posted the wrong one and fixed it sorry. It worked when I did it your way but I thought that you could define something anywhere in your code and use it anywhere as opposed to the way javascript does it where you have to define THEN use. I cant remember where I was tought that. Quote Link to comment https://forums.phpfreaks.com/topic/176332-solved-dynamic-requirement-of-include-file/#findComment-929389 Share on other sites More sharing options...
YourNameHere Posted October 3, 2009 Author Share Posted October 3, 2009 Either way, Thanks for your help. It's solved. Quote Link to comment https://forums.phpfreaks.com/topic/176332-solved-dynamic-requirement-of-include-file/#findComment-929390 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.