kroymac Posted August 28, 2013 Share Posted August 28, 2013 Lets say my database table looks like this: map_name map_link dm/anubis http://www.mysite.com/files/anubis.pk3 dm/tomb http://www.mysite.com/files/tomb.pk3 dm/bunker http://www.mysite.com/files/bunker.pk3 and the php script will be called maplink.php I need it so when the address is entered like this: http://www.mysite.com/maplink.php?map=dm/anubis it will echo back the map_link like this: http://www.mysite.com/files/anubis.pk3 and so on for any map name added to the end of the address I don't want it to be an active link but just displayed I'm sure this is a simple query script but I am new to this. Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted August 28, 2013 Share Posted August 28, 2013 The following should help guide you for getting the "map" variable from the URL: http://php.net/manual/en/reserved.variables.get.php Once you feel comfortable with GET variables, you could then use the information to perform the MySQL query. Here's some information on executing a query with MySQLi: http://www.php.net/manual/en/mysqli.query.php Or you could use PDO: http://php.net/manual/en/pdo.query.php Quote Link to comment Share on other sites More sharing options...
kroymac Posted August 28, 2013 Author Share Posted August 28, 2013 assume the connection has been made This is what I've been trying to make work but it returns nothing $db = mysql_connect($db_host, $db_user, $db_pass) OR DIE ("Unable to connect to database! Please try again later."); mysql_select_db($db_database); $sql = mysql_query("SELECT * FROM gamemaps WHERE map_name = '".$map."'"); $row = mysql_fetch_array($sql); $map = $_GET['map_link']; echo $map; Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted August 28, 2013 Share Posted August 28, 2013 It looks like you're using $map before it's initialized. Try moving the following line above the query. $map = $_GET['map_link']; Quote Link to comment Share on other sites More sharing options...
kroymac Posted August 29, 2013 Author Share Posted August 29, 2013 (edited) still nothing Edited August 29, 2013 by kroymac Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted August 29, 2013 Share Posted August 29, 2013 First, what is the name of the GET variable in the real URL? Your code suggests that it's "map_link". However, your original post (below) suggests that it's "map". I need it so when the address is entered like this: http://www.mysite.com/maplink.php?map=dm/anubis Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted August 29, 2013 Share Posted August 29, 2013 Also, are you trying to echo the database value...or the GET variable? If you're trying to display the database value, you need to use the $row variable. Quote Link to comment Share on other sites More sharing options...
kroymac Posted August 29, 2013 Author Share Posted August 29, 2013 (edited) $db = mysql_connect($db_host, $db_user, $db_pass) OR DIE ("Unable to connect to database! Please try again later."); mysql_select_db($db_database); $map = $_GET['map']; $sql = mysql_query("SELECT map_name FROM gamemaps WHERE map_link = '".$map."'"); $row = mysql_fetch_array($sql); echo $map; now when I enter the address: http://www.mysite.com/maplink.php?map=dm/anubis it just returns: dm/anubis and I want it to return: http://www.mysite.com/files/anubis.pk3 sorry, I am totally new to this and it's a bit confusing. yes i just want it to return the database value Edited August 29, 2013 by kroymac Quote Link to comment Share on other sites More sharing options...
Solution kroymac Posted August 30, 2013 Author Solution Share Posted August 30, 2013 this finally worked $map = $_GET['map']; $sql = mysql_query("SELECT map_link FROM gamemaps WHERE map_image = '".$map."'"); $row = mysql_fetch_array($sql); echo $row['maps_link']; thanks for your help and patience Quote Link to comment Share on other sites More sharing options...
vinny42 Posted August 31, 2013 Share Posted August 31, 2013 Yes that works, but don't forget to add errorchecking and escape the $map value. Otherwise you're completely exposed to SQL-Injection. Quote Link to comment 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.