Jump to content

Getting Post name from link?


Kryllster

Recommended Posts

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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'] . "'");

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.