Kryllster Posted January 17, 2011 Share Posted January 17, 2011 Ok I have links from different pictures and I am wanting to retrieve data from a database depending on the link clicked how would I go about doing this here is my database code. <?php // include database connection to mob database $host = "localhost"; // Host name $db_username = ""; // Mysql username $db_password = ""; // Mysql password $db_name = ""; // Database name // Connect to server and select databse. $sql = mysql_connect("$host", "$db_username", "$db_password"); // error message if (!$sql) { die('Could not connect: ' . mysql_error()); exit(); } // failure to select db else{ mysql_select_db("$db_name")or die("cannot select DB"); } // perform sql $sql = "select * from monstors where mob_name = '" . $_GET['name'] . "'"; $result = mysql_query($sql) or trigger_error($sql . '<br />' . mysql_error()); if(mysql_num_rows($result) > 0) { $row = mysql_fetch_assoc($result); $mob = new mob($row); } ?> Thanks for any advice! Quote Link to comment https://forums.phpfreaks.com/topic/224655-getting-post-name-from-link/ Share on other sites More sharing options...
Garethp Posted January 17, 2011 Share Posted January 17, 2011 <a href="link.php?name=something"><img src="something" /></a> Quote Link to comment https://forums.phpfreaks.com/topic/224655-getting-post-name-from-link/#findComment-1160468 Share on other sites More sharing options...
Kryllster Posted January 17, 2011 Author Share Posted January 17, 2011 I tried that but I had to make a new script it worked on the first one but the second one didn't work. I am trying to make a dynamic fighting script that will handle all fights in a game I am working on. Any other advice I am also using an oop library I made just to try it out but it looks like im gonna have to do this procedurally some anyway. just some more code to throw in there for any comments. <?php class mob { // Monstors public $mob_name; public $attack; public $mob_hp; public $mob_level; // construct provided by phpfreaks forum function __construct(array $items) { foreach($items as $k => $v) { $this->{$k} = $v; } } function set_mob_name($mob_name) { $this->mob_name = $mob_name; } function get_mob_name() { return $this->mob_name; } function set_attack($attack) { $this->attack = $attack; } function get_attack() { return $this->attack; } function set_mob_hp($mob_hp) { $this->mob_hp = $mob_hp; } function get_mob_hp() { return $this->mob_hp; } function set_mob_level($mob_level) { $this->mob_level = $mob_level; } function get_mob_level() { return $this->mob_level; } } ?> This works when I make an array and put the values in and such. Any ideas? Could an xml form handle this? Im stumped. Quote Link to comment https://forums.phpfreaks.com/topic/224655-getting-post-name-from-link/#findComment-1160479 Share on other sites More sharing options...
Far Cry Posted January 17, 2011 Share Posted January 17, 2011 I've edited your SQL statement, the select, from and where clauses should be in all caps also the query should be surrounded by parameters followed by the call of the query function "mysql_query();" $sql = mysql_query("SELECT * FROM monstors WHERE mob_name = '" . $_GET['name'] . "'"); Quote Link to comment https://forums.phpfreaks.com/topic/224655-getting-post-name-from-link/#findComment-1160488 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.